簡體   English   中英

Qt QCompleter不能設置它的大小?

[英]Qt QCompleter can't have its size set?

我有一個附加到QLineEditQCompleter ,它工作正常,除了建議彈出窗口是行編輯的寬度,而我需要它們更寬。 完成者中沒有任何方法似乎允許我改變它。 我能做什么?

您可以在其中設置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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM