![](/img/trans.png)
[英]QT How to disable setFixedSize(Form->size()) once its set
[英]Qt QCompleter can't have its size set?
我有一個附加到QLineEdit
的QCompleter
,它工作正常,除了建議彈出窗口是行編輯的寬度,而我需要它們更寬。 完成者中沒有任何方法似乎允許我改變它。 我能做什么?
您可以在其中設置QAbstractItemView
子類,您可以在其中設置寬度,然后將此自定義類設置為QCompleter::setPopup(QAbstractItemView * popup)
它可以在QAbstractView * popup()項中設置。 我的嘗試:
// 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);
結果(在Windows 7上測試,放大2倍):
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.