Results 1 to 3 of 3

Thread: Layout QActions in a QToolBar

  1. #1
    Join Date
    Mar 2010
    Qt products

    Default Layout QActions in a QToolBar

    I've a QToolBar with 30 Actions : one column of 30 Icons.
    I want organize this Actions in 2 Colums of 15 items for column.
    I think to create a Vertical Layout, and insert in this Layout 15 Horizontal Layouts.
    Then in every Horizontal Layouts add two QActions.

    But the layout with the QActions in the QToolBar don't works :
    I Post a little example, with only one icon (QAction) :

    1. I Create a Widget (w1) with only a QAction.
    2. I Create an HorizontalLayout (hl) and i set to it the Widget (w1)
    3. I Create a new Widget (w2)
    4. I Set to w2 the layout (hl) that contains the other widget (w1).
    5. I Add the w2 widget to the toolBar.

    Qt Code:
    1. QWidget *w1 = new QWidget();
    2. w1->addAction(myAction); // myAction is QAction*;
    4. hl->addWidget(w1);
    6. QWidget *w2 = new QWidget();
    7. w2->setLayout(hl);
    8. toolBar->addWidget(w2);
    To copy to clipboard, switch view to plain text mode 

    This code don't works. In the Toolbar nothing appears.
    How can I manage the layout in the ToolBar ?
    Thank you

  2. #2
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default Re: Layout QActions in a QToolBar

    QWidget::addAction() doesn't do what you want. You need to manually create a QToolButton for each action, then assign the action to the button and place the button in the layout.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.

  3. #3
    Join Date
    Mar 2010
    Qt products

    Default Re: Layout QActions in a QToolBar

    Thank you!
    Works very well!

Similar Threads

  1. QToolBar Layout(when part of QMainWindow)
    By iridium in forum Qt Programming
    Replies: 3
    Last Post: 18th April 2013, 13:19
  2. Position of qActions inside a QToolBar
    By jano_alex_es in forum Newbie
    Replies: 9
    Last Post: 23rd April 2010, 10:29
  3. Draggable QActions in Qt
    By vajindarladdad in forum Newbie
    Replies: 6
    Last Post: 14th August 2009, 11:15
  4. Widgets Layout in a QToolBar.
    By cydside in forum Qt Programming
    Replies: 1
    Last Post: 27th June 2009, 08:46
  5. Tooltips on QActions
    By drhex in forum Newbie
    Replies: 1
    Last Post: 8th February 2006, 18:05

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.