Qt QCompleter can not set its size?

I have QCompleterone attached to QLineEdit, and it works fine, except that the tooltips are the width of the line edit, while I need them to be wider. The add-on does not have any methods that seem to allow me to change this. What can I do?

+4
source share
2 answers

You can subclass QAbstractItemViewin which you can set the width and then set this custom class toQCompleter::setPopup(QAbstractItemView * popup)

+3
source

It can be set in the QAbstractView * popup () element. My attempt:

// compute needed width
const QAbstractItemView * popup = _completer->popup();
int padding = popup->width() - popup->viewport()->width();
int scrollbarWidth = qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent);
int frameWidth = popup->frameWidth();
int textWidth = popup->fontMetrics().boundingRect(QLocale().toString(string)).width();
int desiredWidth = textWidth + 4 * padding + 2 * frameWidth + scrollbarWidth;

// set it
_completer->popup()->setMinimumWidth(desiredWidth);

Result (tested on Windows 7, increase 2x): n30Kk.png

0
source

Source: https://habr.com/ru/post/1599278/


All Articles