Adding a QMenuBar to a ui...
-
I'm following:
https://www.youtube.com/watch?v=E9eQO5czNrwMy ui file:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>clsMainWnd</class> <widget class="QMainWindow" name="clsMainWnd"> <property name="windowModality"> <enum>Qt::NonModal</enum> </property> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>196</width> <height>137</height> </rect> </property> <property name="focusPolicy"> <enum>Qt::NoFocus</enum> </property> <property name="windowTitle"> <string notr="true"/> </property> <property name="toolTip"> <string notr="true"/> </property> <property name="statusTip"> <string notr="true"/> </property> <widget class="QWidget" name="centralWidget"> <property name="styleSheet"> <string notr="true">background-color:#ff333333</string> </property> <widget class="QLabel" name="lblHdr"> <property name="geometry"> <rect> <x>7</x> <y>0</y> <width>161</width> <height>38</height> </rect> </property> <property name="text"> <string notr="true"/> </property> <property name="pixmap"> <pixmap resource="clsmainwnd.qrc">:/CMPY_LOGO</pixmap> </property> <property name="scaledContents"> <bool>false</bool> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> </widget> <widget class="QLabel" name="lblAppTitle"> <property name="geometry"> <rect> <x>8</x> <y>40</y> <width>161</width> <height>20</height> </rect> </property> <property name="toolTip"> <string>XML Multi-Platform Application Manager</string> </property> <property name="styleSheet"> <string notr="true">color:#ffffffff;</string> </property> <property name="text"> <string>XMLMPAM</string> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> <property name="openExternalLinks"> <bool>true</bool> </property> </widget> <widget class="QLabel" name="lblWidth"> <property name="geometry"> <rect> <x>8</x> <y>80</y> <width>91</width> <height>20</height> </rect> </property> <property name="styleSheet"> <string notr="true">color:#ffffffff;</string> </property> <property name="text"> <string>Display width: </string> </property> <property name="alignment"> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> </property> </widget> <widget class="QLabel" name="lblHeight"> <property name="geometry"> <rect> <x>8</x> <y>60</y> <width>91</width> <height>20</height> </rect> </property> <property name="styleSheet"> <string notr="true">color:#ffffffff;</string> </property> <property name="text"> <string>Display height:</string> </property> <property name="alignment"> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> </property> </widget> <widget class="QLabel" name="lblWidthVal"> <property name="geometry"> <rect> <x>110</x> <y>80</y> <width>60</width> <height>20</height> </rect> </property> <property name="styleSheet"> <string notr="true">color:#ffffffff;</string> </property> <property name="text"> <string>0</string> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> <widget class="QLabel" name="lblHeightVal"> <property name="geometry"> <rect> <x>110</x> <y>60</y> <width>60</width> <height>20</height> </rect> </property> <property name="styleSheet"> <string notr="true">color:#ffffffff;</string> </property> <property name="text"> <string>0</string> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </widget> <widget class="QMenuBar" name="mnuBar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>196</width> <height>24</height> </rect> </property> <widget class="QMenu" name="menuFile"> <property name="title"> <string>File</string> </property> <addaction name="actionNew"/> <addaction name="actionOpen"/> <addaction name="actionExit"/> </widget> <addaction name="menuFile"/> </widget> <action name="actionNew"> <property name="text"> <string>New</string> </property> <property name="shortcut"> <string>Ctrl+N</string> </property> </action> <action name="actionOpen"> <property name="text"> <string>Open</string> </property> <property name="shortcut"> <string>Ctrl+O</string> </property> </action> <action name="actionExit"> <property name="text"> <string>Exit</string> </property> <property name="shortcut"> <string>Ctrl+X</string> </property> </action> </widget> <layoutdefault spacing="6" margin="11"/> <resources> <include location="clsmainwnd.qrc"/> </resources> <connections/> </ui>
Whilst I can see the menu and the submenu in Qt Creator, when I build and launch the application I am not seeing the menu bar or the menus.
This is my class constructor:
clsMainWnd::clsMainWnd(QWidget* pobjParent) : QMainWindow(pobjParent) , ui(new Ui::clsMainWnd) { //Check that window doesn't already exist Q_ASSERT_X(mspobjAppWnd==nullptr, "clsMainWnd", "mspobjAppWnd"); //Modify the window to occupy full screen with no window dressing // setWindowFlags(Qt::CustomizeWindowHint // | Qt::FramelessWindowHint // | Qt::WindowStaysOnTopHint); //Get desktop geometry msrctDesktop = screen()->geometry(); //Save pointer to main window mspobjAppWnd = this; //Set-up the user interface ui->setupUi(this); QString strTemp; strTemp = QString::asprintf("%dpx", msrctDesktop.width()); ui->lblWidthVal->setText(static_cast<const QString>(strTemp)); strTemp = QString::asprintf("%dpx", msrctDesktop.height()); ui->lblHeightVal->setText(static_cast<const QString>(strTemp)); //Set-up one second timer to perform house keeping functions QTimer::singleShot(REMOVE_SPLASH_TIME, this, &clsMainWnd::onRemoveSplash); //Start socket server thread to listen to modules //This application is the socket server, when modules are started they //will send a message to this application via the server socket mspsckServer = new clsListener(clsListener::uint16NextPort(), this); }
This is just a demo, once its working I have other plans.
-
@jsulm , I think I've found it, it could be this code in the constructor that Is changing the geometry and probably displaying the labels over the menu:
ui->setupUi(this); QString strTemp; strTemp = QString::asprintf("%dpx", msrctDesktop.width()); ui->lblWidthVal->setText(static_cast<const QString>(strTemp)); strTemp = QString::asprintf("%dpx", msrctDesktop.height()); ui->lblHeightVal->setText(static_cast<const QString>(strTemp));
[Edit] no that wasn't it either.
And obviously I read it completely wrong, that simply sets the label text.
-
I'm following:
https://www.youtube.com/watch?v=E9eQO5czNrwMy ui file:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>clsMainWnd</class> <widget class="QMainWindow" name="clsMainWnd"> <property name="windowModality"> <enum>Qt::NonModal</enum> </property> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>196</width> <height>137</height> </rect> </property> <property name="focusPolicy"> <enum>Qt::NoFocus</enum> </property> <property name="windowTitle"> <string notr="true"/> </property> <property name="toolTip"> <string notr="true"/> </property> <property name="statusTip"> <string notr="true"/> </property> <widget class="QWidget" name="centralWidget"> <property name="styleSheet"> <string notr="true">background-color:#ff333333</string> </property> <widget class="QLabel" name="lblHdr"> <property name="geometry"> <rect> <x>7</x> <y>0</y> <width>161</width> <height>38</height> </rect> </property> <property name="text"> <string notr="true"/> </property> <property name="pixmap"> <pixmap resource="clsmainwnd.qrc">:/CMPY_LOGO</pixmap> </property> <property name="scaledContents"> <bool>false</bool> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> </widget> <widget class="QLabel" name="lblAppTitle"> <property name="geometry"> <rect> <x>8</x> <y>40</y> <width>161</width> <height>20</height> </rect> </property> <property name="toolTip"> <string>XML Multi-Platform Application Manager</string> </property> <property name="styleSheet"> <string notr="true">color:#ffffffff;</string> </property> <property name="text"> <string>XMLMPAM</string> </property> <property name="alignment"> <set>Qt::AlignCenter</set> </property> <property name="openExternalLinks"> <bool>true</bool> </property> </widget> <widget class="QLabel" name="lblWidth"> <property name="geometry"> <rect> <x>8</x> <y>80</y> <width>91</width> <height>20</height> </rect> </property> <property name="styleSheet"> <string notr="true">color:#ffffffff;</string> </property> <property name="text"> <string>Display width: </string> </property> <property name="alignment"> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> </property> </widget> <widget class="QLabel" name="lblHeight"> <property name="geometry"> <rect> <x>8</x> <y>60</y> <width>91</width> <height>20</height> </rect> </property> <property name="styleSheet"> <string notr="true">color:#ffffffff;</string> </property> <property name="text"> <string>Display height:</string> </property> <property name="alignment"> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> </property> </widget> <widget class="QLabel" name="lblWidthVal"> <property name="geometry"> <rect> <x>110</x> <y>80</y> <width>60</width> <height>20</height> </rect> </property> <property name="styleSheet"> <string notr="true">color:#ffffffff;</string> </property> <property name="text"> <string>0</string> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> <widget class="QLabel" name="lblHeightVal"> <property name="geometry"> <rect> <x>110</x> <y>60</y> <width>60</width> <height>20</height> </rect> </property> <property name="styleSheet"> <string notr="true">color:#ffffffff;</string> </property> <property name="text"> <string>0</string> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </widget> <widget class="QMenuBar" name="mnuBar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>196</width> <height>24</height> </rect> </property> <widget class="QMenu" name="menuFile"> <property name="title"> <string>File</string> </property> <addaction name="actionNew"/> <addaction name="actionOpen"/> <addaction name="actionExit"/> </widget> <addaction name="menuFile"/> </widget> <action name="actionNew"> <property name="text"> <string>New</string> </property> <property name="shortcut"> <string>Ctrl+N</string> </property> </action> <action name="actionOpen"> <property name="text"> <string>Open</string> </property> <property name="shortcut"> <string>Ctrl+O</string> </property> </action> <action name="actionExit"> <property name="text"> <string>Exit</string> </property> <property name="shortcut"> <string>Ctrl+X</string> </property> </action> </widget> <layoutdefault spacing="6" margin="11"/> <resources> <include location="clsmainwnd.qrc"/> </resources> <connections/> </ui>
Whilst I can see the menu and the submenu in Qt Creator, when I build and launch the application I am not seeing the menu bar or the menus.
This is my class constructor:
clsMainWnd::clsMainWnd(QWidget* pobjParent) : QMainWindow(pobjParent) , ui(new Ui::clsMainWnd) { //Check that window doesn't already exist Q_ASSERT_X(mspobjAppWnd==nullptr, "clsMainWnd", "mspobjAppWnd"); //Modify the window to occupy full screen with no window dressing // setWindowFlags(Qt::CustomizeWindowHint // | Qt::FramelessWindowHint // | Qt::WindowStaysOnTopHint); //Get desktop geometry msrctDesktop = screen()->geometry(); //Save pointer to main window mspobjAppWnd = this; //Set-up the user interface ui->setupUi(this); QString strTemp; strTemp = QString::asprintf("%dpx", msrctDesktop.width()); ui->lblWidthVal->setText(static_cast<const QString>(strTemp)); strTemp = QString::asprintf("%dpx", msrctDesktop.height()); ui->lblHeightVal->setText(static_cast<const QString>(strTemp)); //Set-up one second timer to perform house keeping functions QTimer::singleShot(REMOVE_SPLASH_TIME, this, &clsMainWnd::onRemoveSplash); //Start socket server thread to listen to modules //This application is the socket server, when modules are started they //will send a message to this application via the server socket mspsckServer = new clsListener(clsListener::uint16NextPort(), this); }
This is just a demo, once its working I have other plans.
-
@jsulm , I think I've found it, it could be this code in the constructor that Is changing the geometry and probably displaying the labels over the menu:
ui->setupUi(this); QString strTemp; strTemp = QString::asprintf("%dpx", msrctDesktop.width()); ui->lblWidthVal->setText(static_cast<const QString>(strTemp)); strTemp = QString::asprintf("%dpx", msrctDesktop.height()); ui->lblHeightVal->setText(static_cast<const QString>(strTemp));
[Edit] no that wasn't it either.
And obviously I read it completely wrong, that simply sets the label text.
-
@jsulm , I think I've found it, it could be this code in the constructor that Is changing the geometry and probably displaying the labels over the menu:
ui->setupUi(this); QString strTemp; strTemp = QString::asprintf("%dpx", msrctDesktop.width()); ui->lblWidthVal->setText(static_cast<const QString>(strTemp)); strTemp = QString::asprintf("%dpx", msrctDesktop.height()); ui->lblHeightVal->setText(static_cast<const QString>(strTemp));
[Edit] no that wasn't it either.
And obviously I read it completely wrong, that simply sets the label text.
-
@SPlatten In MacOS the menu of every application is in the top bar, not in the application window itself.
-
S SPlatten has marked this topic as solved on