How to change the size of a QComboBox's QScrollBar?

你离开我真会死。 提交于 2019-12-18 07:07:43

问题


I'm using a QComboBox with some items to the point that, when the widget that shows all available items in the QComboBox appears, only some of the items are visible with the other accesible through a QScrollBar.

The problem is that the QScrollBar is to thin and I want to make it larger. I did some research on the web and I did found some ways to change the QScrollBar's width (see references below), but the problem is that I simply can't find the method to access the QComboBox's QScrollBar.

So, given this problem, how can I do this change? (I guess you may either present me with a way that don't require me to access the QScrollBar or show how may I access it).

References:

  • vertical scrollbar width - Direct access and style
  • How to get scroll bar real width in Qt? - Again by pixlMetric (only access)
  • How to increase QTableWidget Vertical Scrollbar width? - Using stylesheet (a preferable method if there is a way to make it apply to all QScrollBars available in the project)
  • Other options are discussed here

回答1:


  1. Get the combobox's QAbstractItemView via view()

  2. That class inherits from QAbstractScrollArea, thus inherits the verticalScrollBar method

e.g.

QAbstractItemView *qv = combobox.view();
QScrollBar *scrollbar = qv->verticalScrollBar();
// Adjust size via setStyleSheet or hint/width



回答2:


The scroll bar isn't a member of the QComboBox class, it's a member of the underlying QAbstractItemView. Try something like the following (pseudo-code):

QListView* abby = new QListView();
QWidgetList list = abby->scrollBarWidgets(Qt::AlignRight);
for (auto itr = list.begin(); itr != list.end(); itr++)
{
    (*itr)->setMinimumWidth(100);
}
QComboBox combo;
combo.setView(abby);

The scrollbarwidgets returns a widget list of the scroll bars for that alignment. You can then set the properties on the scroll bar pointers.



来源:https://stackoverflow.com/questions/26047184/how-to-change-the-size-of-a-qcomboboxs-qscrollbar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!