Results 1 to 4 of 4

Thread: how align some buttons in QToolbar from right to left?

  1. #1

    Default how align some buttons in QToolbar from right to left?

    I have to local two QToolbars at the top of the main window. The button in one ist aligned right-to-left.
    Thank for the Help

  2. #2
    Join Date
    Feb 2008
    Posts
    98
    Thanks
    2
    Thanked 24 Times in 24 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how align some buttons in QToolbar from right to left?

    Create a blank widget and set its horizontal size policy to QSizePolicy::Expanding. Add that widget before all the actions. This way, the widget will act like a spacer, making the rest of toolbuttons appear at the right side. For example:

    Qt Code:
    1. #include <QtGui>
    2. #include "mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent)
    5. : QMainWindow(parent)
    6. {
    7. QToolBar *toolBar = addToolBar(tr("Main toolbar"));
    8.  
    9. QWidget *spacerWidget = new QWidget(this);
    10. spacerWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    11. spacerWidget->setVisible(true);
    12. QAction *myAction = new QAction(tr("Exit"), this);
    13.  
    14. toolBar->addWidget(spacerWidget);
    15. toolBar->addAction(myAction);
    16. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2008
    Posts
    98
    Thanks
    2
    Thanked 24 Times in 24 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how align some buttons in QToolbar from right to left?

    Oops! Sorry, I didn't realise you're talking about Qt 3.

  4. #4

    Default Re: how align some buttons in QToolbar from right to left?

    nonetheless, thx

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.