Question

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()?

Was it helpful?

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.

OTHER TIPS

The widget associated with a given action is accessible through QToolBar::widgetForAction (since Qt 4.2). So, you can pass your actions to this method, get the QWidgets returned by it, convert them to QToolBar, and handle them like you normally would (code not tested):

// ...

auto toolButton =
    static_cast<QToolButton *>(
        m_ui.toolbar->widgetForAction(m_ui.my_Action));

// Will make the toolButton always appear raised:
toolButton->setAutoRaise(false);

// ...

As far as I've been testing, some methods might not work (i.e., QWidget::hide), so do your own testing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top