自定义QToolBar扩展按钮

时间:2018-06-12 11:18:37

标签: c++ css qt

早上好,或者下午好。:)

我正在尝试自定义QToolBar。 我设法自定义工具栏的按钮,但我找不到将扩展按钮设置为两个默认箭头的方法...

以下是帮助您了解的说明: enter image description here

在此工具栏上,您可以在第二个工具栏的末尾看到一个双箭头,但在第一个工具栏的末尾没有(在变量之后)...我想将qt_toolbar_ext_button设置为此路径中的图像:/images/images/extension-arrows.png

我用来定制它们的代码是:

m_toolbar1->setStyleSheet(
    "QToolBar {border-bottom: 1px solid #808d97;"
    "border-top: 1px solid #808d97; background-color: #3a4f5e;} "

    "QToolButton {background:#3a4f5e; border: 1px solid #585858;"
    "border-style: outset; border-radius: 4px; min-width: 5em; min-height: 1.5em; color: white}"

    "QToolButton:hover {background: #5d7180; border: 1px groove #293843;}"

    "QToolButton:pressed {background:#475864; border: 1px groove #293843;}"
    "QToolButton#qt_toolbar_ext_button {"
        "border: none;"
        "background: url(:/images/images/extension-arrows.png);"
        "padding-top: 20;"
        "width: 20px;"
        "font: bold 14px;"
        "color: red;}");

m_toolbar2->setStyleSheet("background-color: #3a4f5e; color:white;");

此代码的灵感来自:How to set the QToolButton's icons using style sheet?

提前感谢您的帮助! :d

1 个答案:

答案 0 :(得分:0)

我找到了这个解决方案,但是通过小部件API。

ui->toolBar->findChild<QToolButton*>("qt_toolbar_ext_button")->setIcon(QIcon(":/icon/myico.png")); 
相关问题