ulak blade
ulak blade

Reputation: 2655

Qt QCompleter can't have its size set?

I have a QCompleter attached to a QLineEdit and it works fine, except the suggestion popups are the width of the line edit, while I need them to be wider. There aren't any methods in the completer that seem to allow me to change this. What can I do?

Upvotes: 4

Views: 1563

Answers (2)

Tomas Tintera
Tomas Tintera

Reputation: 829

It can be set in the QAbstractView * popup() item. My try:

// 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, magnify 2x):

Upvotes: 1

DigviJay Patil
DigviJay Patil

Reputation: 1006

You can Subclass QAbstractItemView in which you can set width and then set this customized class to QCompleter::setPopup(QAbstractItemView * popup)

Upvotes: 3

Related Questions