qt - Create QMenu class outside of main UI -
first off want mention i'm java background.
i'm designing first app in qtcreator, , want add menus it.
i want create qmenu widget in separate file, keep main ui window simple , clean.
this possible defining qmenu in xml file , including in main .ui file using file(load) method, or similar.
however in qt creator can't find how create new file inherits qmenu?
what correct way it?
i want each components simple , specific.
so ui 'main' method entry point, draw main window, , include initial menu item, intend show simple 'welcome' type page having menu item connected data source.
i expect menu contents change depending on type of data, (or rather part of program user acting with). intend handle these different menu's in different files related user interaction.
thanks in advance.
david
i assume want use qmenubar represents main menu or qmainwindow. qmenu not embedded in other widgets.
this quite possible. create designer form class derived qwidget. let's call my_menu
. open ui file using text editor , replace qwidget qmenubar in line <widget class="qwidget" name="my_menu">
. may need remove title property , other properties cannot applied qmenubar. switch cpp , h files , make class derived qmenubar instead of qwidget.
next, open main window ui in form editor, find qmenubar entry in object tree , choose "promote to" in context menu. type new class name , apply. should work now.
files should that:
header:
#include <qmenubar> namespace ui { class my_menu; } class my_menu : public qmenubar { q_object public: explicit my_menu(qwidget *parent = 0); ~my_menu(); private: ui::my_menu *ui; };
source:
my_menu::my_menu(qwidget *parent) : qmenubar(parent), ui(new ui::my_menu) { ui->setupui(this); } my_menu::~my_menu() { delete ui; }
ui:
<?xml version="1.0" encoding="utf-8"?> <ui version="4.0"> <class>my_menu</class> <widget class="qmenubar" name="my_menu"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>135</width> <height>94</height> </rect> </property> <widget class="qmenu" name="menuc"> <property name="title"> <string>c</string> </property> </widget> <action name="actiona"> <property name="text"> <string>a</string> </property> </action> <action name="actionb"> <property name="text"> <string>b</string> </property> </action> <addaction name="actiona"/> <addaction name="actionb"/> <addaction name="menuc"/> </widget> <resources/> <connections/> </ui>
Comments
Post a Comment