Results 1 to 4 of 4

Thread: QToolBar Layout(when part of QMainWindow)

  1. #1
    Join Date
    Aug 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QToolBar Layout(when part of QMainWindow)

    Iam trying to add QAction icon with spaces. I have about 5 icons and I want 2 icons to be aligned to the extreme right and the other three to be aligned to the extreme left.
    Iam trying to do the above to the QToolBar which is added to the QMainWindow.

    When I look at the source code, it seems QToolBar uses the QToolBarLayout and doesnt seem to be very flexible. I tried adding a spacer to a widget, it doesnt work, I tried all sorts of other things, it just would not align properly.
    Suggestions are welcome

  2. #2
    Join Date
    Aug 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QToolBar Layout(when part of QMainWindow)

    Well,
    Iam going to try to answer this myself, I had to workaround the problem of not being able to set Layouts in a QToolbar added to QMainWindow by not using a QMainWindow.

    So when I created a QWidget with QVBoxLayouts, I was able to set layout to the QToolBar and I was able to align QActions.

  3. #3
    Join Date
    Aug 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QToolBar Layout(when part of QMainWindow)

    It's never too late ^^.

    I had the same problem you are describing. I needed to put widgets in the bottom of the QToolBar. There is nothing to help us. I finally also used a intermediate QWidget :

    Qt Code:
    1. ...
    2. QWidget *w = new QWidget(this); // "this" is a pointer to a QToolBar
    3. QVBoxLayout *vbox = new QVBoxLayout(w);
    4.  
    5. vbox->addStretch();
    6. ...
    7. vbox->addWidget(...);
    8. vbox->addWidget(...);
    9. ...
    10. w->setLayout(vbox);
    11. this->addWidget(w);
    12. ...
    To copy to clipboard, switch view to plain text mode 

    and it worked for me ! Is there a better/"normal" way to achieve that ?

  4. #4
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: QToolBar Layout(when part of QMainWindow)

    I was also using the same approach, but recently I noticed in Qt5 it creates problems: QToolButton doesn't look like a real button. When you click it the button is not redrawn as pressed, no mouse hover decorations either. Tested on Mac OS X 10.7, 10.8, Qt5.0.1, Qt5.0.2. Any ideas how to fix this?

Similar Threads

  1. Insert separate QToolBar into QMainWindow
    By YuriyRusinov in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 11:37

Bookmarks

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.