Which solution is best to resize QToolButton full-width?



  • I wanted same width and full-width QToolButtons but my phone abandoned me :(

    First I thought set QSS to QToolButton with "width: 100%;" but it didn't be resized I wish. Then I thought some solutions like reimplementing QToolBar's resize event, using QWidgetAction with QPushButton, Inserting HBoxLayout to QToolbar and etc.

    Umm... I guess better solution is exist, maybe. Any other solutions?



  • Sounds like your issue is also related to the request here:
    "http://bugreports.qt.nokia.com/browse/QTBUG-13120":http://bugreports.qt.nokia.com/browse/QTBUG-13120
    It's being worked on by the Qt team at the moment. If you have additional comments or suggestions, please post them as a comment to the report!



  • Thx ajkl. I have just commented.

    Qt team doesn't think it is not so important. But I think it's very important issue for Symbian developers with Qt… :-/



  • We do think it is important (but not critical).

    Note that you can easily set your QToolButtons inside QToolBars occupy fullwidth using sizepolicies.

    For example:
    @
    QToolBar *toolbar = new QToolBar(this);
    QToolButton *toolbutton = new QToolButton(this);
    toolbutton->setText("ToolButton");
    toolbutton->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
    toolbar ->addWidget(toolbutton);
    toolbar ->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
    @

    Hopefully this helps.

    Please follow the linked bug for additional information.



  • Thx for your help, Fuzzbender.

    Your code works well but setSizePolicy() doesn't affect QToolButton that created through addAction() method.

    I used setSizePolicy() in actionEvent() and resizeEvent() with QToolButton got by widgetForAction(). Am I worng?



  • Yes, you are right. ToolBar uses layout to internally set the size of QAction derived buttons to "minimal".


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.