0

QToolbar 使用扩展按钮而不是使用水平滚动条

我使用 QScrollArea 来显示 QToolbar 以便工具栏使用滚动条而不是扩展按钮。扩展按钮显示为黄色圆圈。添加的水平滚动条以红色突出显示。

QToolBar *bar = new QToolBar();

QScrollArea *scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Light);

diag->layout()->addWidget(scrollArea); // parent dialog 

add_tool_bar(bar); // adding QActions

scrollArea->setWidget(bar); // toolbar is added to scroll area 

scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);

bar->setStyleSheet("QToolBar{spacing:30px;}"); // spacing between QAction in QToolbar

bar->setFixedWidth(1900); // trying to use fixed length so that extension button won't be shown but it didn't work
4

0 回答 0