PDA

View Full Version : QMainWindow::addToolbar/removeToolbar



psih128
17th November 2009, 16:54
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:


ui->pushButton_1->isChecked() ? this->addToolBar(t1) : this->removeToolBar(t1);

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

Rembobo
18th November 2009, 07:01
I have used to create a toolbar

t1 = addToolBar("Toolbar 1"); //new QToolBar("Toolbar 1", this);
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

void MainWindow::on_pushButton_1_clicked()
{
if (ui->pushButton_1->isChecked()) {
this->addToolBar(t1);
t1->show();
}
else
this->removeToolBar(t1);
}

psih128
18th November 2009, 18:15
Oh wow.. the docs barely mention this behavior..
And yea, creating the toolbars without a parent specified is better that otherwise.

Thanks a lot!