首页 > 解决方案 > 如何禁用 QToolBar 中的扩展按钮?

问题描述

我想知道如何禁用QToolBar中的扩展按钮,它显示为工具栏中的最后一项,当工具栏太小而无法显示所有项目时?我已经尝试通过 find child 方法,但这不起作用。

标签: c++qtqtoolbar

解决方案


If you want to hide the button that allows you to expand the QToolBar you must first obtain it using the objectName "qt_toolbar_ext_button", and to hide it you must set to size 0, 0 since the hide() method will fail:

if(QToolButton *button = toolbar->findChild<QToolButton *>("qt_toolbar_ext_button")){
    button->setFixedSize(0, 0);
    // button->setEnabled(false);
}

推荐阅读