May 31, 2011

umen242 umen242
Ant Farmer
328 posts

Added QMenuBar in QDialog it showing but sub menus dosn’t open

 

i added QMenuBar in QDialog using layout that is set in Designer and then manully adding the QMenuBar , when running the application and the QDialog runs i see the QMenuBar with only the menu header without the opening sub menu :
here is my code : this is the header file generated from the Designer :

  1. QT_BEGIN_NAMESPACE
  2.  
  3. class Ui_AutoDialog
  4. {
  5. public:
  6.     QVBoxLayout *verticalLayout;
  7.     QWidget *widget_menuBarHolder;
  8.     QVBoxLayout *verticalLayout_2;
  9.     QVBoxLayout *verticalLayout_menuBarLayOut;
  10.     QWebView *webView;
  11.     QWidget *widget;
  12.  
  13.     void setupUi(QDialog *AutoDialog)
  14.     {
  15.         if (AutoDialog->objectName().isEmpty())
  16.             AutoDialog->setObjectName(QString::fromUtf8("AutoDialog"));
  17.         AutoDialog->resize(436, 365);
  18.         verticalLayout = new QVBoxLayout(AutoDialog);
  19.         verticalLayout->setSpacing(0);
  20.         verticalLayout->setContentsMargins(0, 0, 0, 0);
  21.         verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
  22.         widget_menuBarHolder = new QWidget(AutoDialog);
  23.         widget_menuBarHolder->setObjectName(QString::fromUtf8("widget_menuBarHolder"));
  24.         widget_menuBarHolder->setMinimumSize(QSize(0, 20));
  25.         verticalLayout_2 = new QVBoxLayout(widget_menuBarHolder);
  26.         verticalLayout_2->setSpacing(0);
  27.         verticalLayout_2->setContentsMargins(0, 0, 0, 0);
  28.         verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
  29.         verticalLayout_menuBarLayOut = new QVBoxLayout();
  30.         verticalLayout_menuBarLayOut->setSpacing(0);
  31.         verticalLayout_menuBarLayOut->setObjectName(QString::fromUtf8("verticalLayout_menuBarLayOut"));
  32.  
  33.         verticalLayout_2->addLayout(verticalLayout_menuBarLayOut);
  34.  
  35.  
  36.         verticalLayout->addWidget(widget_menuBarHolder);
  37.  
  38.         webView = new QWebView(AutoDialog);
  39.         webView->setObjectName(QString::fromUtf8("webView"));
  40.         webView->setUrl(QUrl("about:blank"));
  41.  
  42.         verticalLayout->addWidget(webView);
  43.  
  44.         widget = new QWidget(AutoDialog);
  45.         widget->setObjectName(QString::fromUtf8("widget"));
  46.         widget->setMinimumSize(QSize(0, 20));
  47.  
  48.         verticalLayout->addWidget(widget);
  49.  
  50.  
  51.         retranslateUi(AutoDialog);
  52.  
  53.         QMetaObject::connectSlotsByName(AutoDialog);
  54.     } // setupUi
  55.  
  56.     void retranslateUi(QDialog *AutoDialog)
  57.     {
  58.         AutoDialog->setWindowTitle(QApplication::translate("AutoDialog", "Dialog", 0, QApplication::UnicodeUTF8));
  59.     } // retranslateUi
  60.  
  61. };
  62.  
  63. namespace Ui {
  64.     class AutoDialog: public Ui_AutoDialog {};
  65. } // namespace Ui
  66.  
  67. QT_END_NAMESPACE

and here is the QDialog constructor , the part where is building the QMenuBAr:

  1. ui.setupUi(this);
  2.  /*ui.verticalLayout_menuBarLayOut->addWidget(SetMenuBar());
  3.  ui.verticalLayout_menuBarLayOut->setMargin(0);
  4.     ui.verticalLayout_menuBarLayOut->setSpacing(0);*/
  5.  
  6.  m_actionClose = new QAction(this);
  7.     m_actionClose->setObjectName(QString::fromUtf8("actionClose"));
  8.     m_actionPreferences = new QAction(this);
  9.     m_actionPreferences->setObjectName(QString::fromUtf8("actionPreferences"));
  10.  
  11.  m_menubar = new QMenuBar(this);
  12.     m_menubar->setObjectName(QString::fromUtf8("menubar"));
  13.     m_menubar->setGeometry(QRect(0, 0, 314, 18));
  14.     m_menuFile = new QMenu(m_menubar);
  15.     m_menuFile->setObjectName(QString::fromUtf8("menuFile"));
  16.     m_menuSettings = new QMenu(m_menubar);
  17.     m_menuSettings->setObjectName(QString::fromUtf8("menuSettings"));
  18.    
  19.     m_menubar->setMinimumSize(QSize(0, 20));
  20.     ui.verticalLayout_menuBarLayOut->setMenuBar(m_menubar);
  21.     m_menubar->addAction(m_menuFile->menuAction());
  22.     m_menubar->addAction(m_menuSettings->menuAction());
  23.     m_menuFile->addSeparator();
  24.     m_menuFile->addAction(m_actionClose);
  25.     m_menuSettings->addAction(m_actionPreferences);
  26.    
  27.     m_actionClose->setText(QApplication::translate("MainWindow", "Close", 0, QApplication::UnicodeUTF8));
  28.     m_actionPreferences->setText(QApplication::translate("MainWindow", "Preferences", 0, QApplication::UnicodeUTF8));
  29.     m_menuFile->setTitle(QApplication::translate("MainWindow", "File", 0, QApplication::UnicodeUTF8));
  30.     m_menuSettings->setTitle(QApplication::translate("MainWindow", "Settings", 0, QApplication::UnicodeUTF8));
  31.    
  32.  
  33.  
  34.  
  35.  bar = new QStatusBar(this);
  36.  bar->setMinimumSize(QSize(0, 20));
  37.  ui.verticalLayout->removeWidget(ui.widget);
  38.  ui.verticalLayout->addWidget(bar);
  39.  ui.verticalLayout->setMargin(0);
  40.     ui.verticalLayout->setSpacing(0);
  41.  
  42.  
  43.  
  44.  pb = new QProgressBar(bar);
  45.  pb->setTextVisible(false);
  46.  pb->hide();
  47.  
  48.  bar->addPermanentWidget(pb);
  49.  

what is wrong here why i can’t see the sub menus.. Close & Preferences?

3 replies

May 31, 2011

peppe peppe
Ant Farmer
1025 posts

Can you make a SMALL testcase? Just one file, immediately compileable, which shows the problem?

In any case, you seem to be using a dedicated layout for holding the menubar. Instead, install it into the toplevel layout.

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

May 31, 2011

umen242 umen242
Ant Farmer
328 posts

if i install it in the top label layout , then when i build the menubar and add it to the top level in mt code :verticalLayout
the menubar apears after the Qwebkit that is in the bottom
beacose i set it after ui.setupUi(this);

September 29, 2011

mehdikarimi mehdikarimi
Lab Rat
1 posts

Use QMenu::AddMenu insted of AddAction in QMenu

 
  ‹‹ Alignment of Table Horizontal Headers      [solved] Making a QML file fill a QDeclarativeView ››

You must log in to post a reply. Not a member yet? Register here!