Search code examples
qtqt4qtoolbar

How can I customize the appearance of the actions in my QToolBar?


I have just changed some toolbars from Q3ToolBars (with QToolButtons explicitly added to them) into Q4 toolbars (with actions added to them straight away instead.)

The old tool buttons had a nice outline around them, but this is not displayed in the new version; the QActions in the Q4 toolbar just look like a line of icons. Is there a way to change the 'button' style in the new version (assuming these actions can be considered as such) and give them the outline? I've looked through the QToolBar reference, but the toolButtonStyle() function only appears to work with whether you want to display icon, text, etc.

...Or will I have to just make actual tool buttons and/or QPushButtons and use addWidget()?


Solution

  • Yes, of course you can edit look of QToolButtons in two different ways:

    1. You can set it style sheet using void QWidget::setStyleSheet(const QString &)
    2. You can reimplement QToolButtons class with new paintEvent function where you will be able to exactly set how your button should looks like.