Results 1 to 3 of 3

Thread: QMainWindow::addToolbar/removeToolbar

  1. #1
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QMainWindow::addToolbar/removeToolbar

    Hi

    I'm having problems with QMainWindow::addToolbar QMainWindow::removeToolbar functons.

    In my application I have couple toolbars which are added/removed, depending on the active application mode (I want to have the toolbars removed from the main window completely, not just hidden with the toggle action). And here the problems begin. as soon as the toolbar is added/removed once, it quits working at all - I call addToolbar, nothing happens.

    Here is he code to add/remove toolbar:

    Qt Code:
    1. ui->pushButton_1->isChecked() ? this->addToolBar(t1) : this->removeToolBar(t1);
    To copy to clipboard, switch view to plain text mode 

    I'm attaching a sample qt project (just run qmake/make).

    Please hint me whether it's my problem, or a bug on Qt side, I'm on Qt 4.5.2

    Thanks
    Anton

    Edit: same issue in Qt 4.6 Beta
    Attached Files Attached Files
    Last edited by psih128; 17th November 2009 at 17:00.

  2. #2
    Join Date
    Mar 2006
    Posts
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow::addToolbar/removeToolbar

    I have used to create a toolbar
    Qt Code:
    1. t1 = addToolBar("Toolbar 1"); //new QToolBar("Toolbar 1", this);
    To copy to clipboard, switch view to plain text mode 
    If I use "new QToolBar("Toolbar 1", this)" the toolbars are created/placed badly (imho).

    A toolbar is not just removed but also hidden. So after readding it to main window show it (make it visible).
    Like
    Qt Code:
    1. void MainWindow::on_pushButton_1_clicked()
    2. {
    3. if (ui->pushButton_1->isChecked()) {
    4. this->addToolBar(t1);
    5. t1->show();
    6. }
    7. else
    8. this->removeToolBar(t1);
    9. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Rembobo for this useful post:

    psih128 (18th November 2009)

  4. #3
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QMainWindow::addToolbar/removeToolbar

    Oh wow.. the docs barely mention this behavior..
    And yea, creating the toolbars without a parent specified is better that otherwise.

    Thanks a lot!

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.