Results 1 to 9 of 9

Thread: Sharing same QToolbar amongst multiple QMainWindows

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2013
    Location
    Colorado
    Posts
    45
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Sharing same QToolbar amongst multiple QMainWindows

    I'm trying to use the same toolbar with a parent QMainWindow and its children QMainWindows.
    Same actions, same stylesheet, same icons, etc.
    The following likely violates all sense of Qt decency, but it kind of works, but only for the first few instantiations of the child QMainWindows.
    I know I'm just using pointers, but is there a better way other than painstakingly building a new toolbar for each child QMainWindow?


    Qt Code:
    1. SubWin::SubWin(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::SubWin)
    4. {
    5. ui->setupUi(this);
    6. setAttribute(Qt::WA_DeleteOnClose);
    7.  
    8. foreach ( QWidget* widget, qApp->allWidgets() )
    9. {
    10. if ( QToolBar* mainTB = qobject_cast<QToolBar*>( widget ) )
    11. {
    12. if( mainTB->objectName() == "mainToolBar" )
    13. {
    14. QToolBar *NewTB = new QToolBar("New Tool Bar", 0);
    15.  
    16. this->addToolBar(Qt::TopToolBarArea, NewTB );
    17. NewTB->setMovable(false);
    18.  
    19. NewTB->setStyleSheet(mainTB->styleSheet());
    20.  
    21. NewTB->addActions(mainTB->actions());
    22. }
    23. break;
    24. }
    25. }
    26.  
    27. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Henry Blue Heeler; 28th December 2013 at 06:54. Reason: grammar

Similar Threads

  1. [QtDesigner] Multiple rows of QToolBar
    By Malutek in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2013, 15:23
  2. how to set the QToolBar's actions to multiple rows
    By fly542 in forum Qt Programming
    Replies: 2
    Last Post: 25th July 2011, 03:00
  3. Replies: 4
    Last Post: 2nd July 2010, 21:16
  4. Replies: 4
    Last Post: 17th October 2009, 22:31
  5. How to change between QMainWindows???
    By webquinty in forum Newbie
    Replies: 3
    Last Post: 16th October 2009, 10:46

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.