2
votes

I am working with qt and have created a menu bar like "File" with some sub menu items "Open", "Save", "SaveAs", "Close", "Quit". I also created actions like "actionNew", "actionOpen", ... and so on. I used the same actions for the tool bar and disable the menu and tool bar items into the constructor with the "disableItems()" function, that works fine and the tool bar and menu items are gray out. If I clicked the sub menu item "New", the tool bar and menu items are enabled and not gray out, that also works fine, but if I clicked the sub menu item "Close" only the tool bar items gray out and the menu items are still enabled :(. How can i fix it? Hope you can help me and sorry for my bad English ;)

MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent), ui(new Ui::MainWindow)
{
  ui->setupUi(this);
  /* disable menu items and tool bar items */
  disableItems();
}
void MainWindow::disableItems()
{
  ui->actionSave->setEnabled(false);
  ui->actionSaveAs->setEnabled(false);
  ui->actionClose->setEnabled(false);
}
void MainWindow::enableItems()
{
  ui->actionSave->setEnabled(true);
  ui->actionSaveAs->setEnabled(true);
  ui->actionClose->setEnabled(true);
}
void MainWindow::on_actionNew_triggered()
{
  enableItems();
}
void MainWindow::on_actionClose_triggered()
{
  disableItems();
}
1

1 Answers

0
votes

I had the same problem.

I was puzzled because the code behaved differently from Linux 64 (where usually I develop), Windows (customer machine), Linux 32 (old development & backup machine). Then I realized the difference in version.

The only way to solve I found was to upgrade from default QtSDK that came with my Ubuntu distribution to the latest downloaded from here.

I suggest to check if the version you are using can be upgraded.

HTH

edit I noticed that they changed something more radical: after the upgrade the menubar is not more shared on 'top screen' but more traditionally inside the 'main window'. Probably the team overlooked a portability problem, that's reasonable considering the wide target they have.