c++ - Qt 4: How to insert QAction in menu of mainwindow -
my problem qaction of custom widget outside , insert in menu of mainwindow. there qactionwidget inserts custom widget in menu.
class qdesigner_widget_export photo_list: public qwidget { q_object public: photo_list(qwidget* parent = 0); ~photo_list(); int count(); qstring returnimagepath(const int i); void sendsignalimageloaded(); public slots: void addimagepath(); void deleteimagepath(); signals: void imageloaded(int count); //private: public: ui::photo_list *m_photo_list_ui; qstringlist m_image_path_list; }; class ui_photo_list { public: qaction *addimageaction; qaction *deleteimageaction; qgridlayout *gridlayout; qlistwidget *listwidget; void setupui(qwidget *photo_list) { if (photo_list->objectname().isempty()) photo_list->setobjectname(qstring::fromutf8("photo_list")); photo_list->resize(274, 210); addimageaction = new qaction(photo_list); addimageaction->setobjectname(qstring::fromutf8("addimageaction")); deleteimageaction = new qaction(photo_list); deleteimageaction->setobjectname(qstring::fromutf8("deleteimageaction")); gridlayout = new qgridlayout(photo_list); gridlayout->setcontentsmargins(0, 0, 0, 0); gridlayout->setobjectname(qstring::fromutf8("gridlayout")); gridlayout->sethorizontalspacing(0); listwidget = new qlistwidget(photo_list); listwidget->setobjectname(qstring::fromutf8("listwidget")); listwidget->settextelidemode(qt::elidemiddle); listwidget->setmovement(qlistview::static); listwidget->setresizemode(qlistview::adjust); listwidget->setviewmode(qlistview::iconmode); gridlayout->addwidget(listwidget, 0, 0, 1, 1); retranslateui(photo_list); qmetaobject::connectslotsbyname(photo_list); } ...
how add qaction *addimageaction in ( * )? (see comment below)
class ui_cpdfa { public: qaction *createpdfaction; qwidget *centralwidget; qgridlayout *gridlayout_2; qgridlayout *gridlayout; qlineedit *pdfpathlineedit; qpushbutton *findpdfpathbutton; photo_list *photo_list; qtoolbar *toolbar; qmenubar *menubar; qmenu *menu; qmenu *menu_2; void setupui(qmainwindow *cpdfa) { if (cpdfa->objectname().isempty()) cpdfa->setobjectname(qstring::fromutf8("cpdfa")); cpdfa->resize(386, 303); createpdfaction = new qaction(cpdfa); createpdfaction->setobjectname(qstring::fromutf8("createpdfaction")); centralwidget = new qwidget(cpdfa); centralwidget->setobjectname(qstring::fromutf8("centralwidget")); gridlayout_2 = new qgridlayout(centralwidget); gridlayout_2->setobjectname(qstring::fromutf8("gridlayout_2")); gridlayout = new qgridlayout(); gridlayout->setobjectname(qstring::fromutf8("gridlayout")); pdfpathlineedit = new qlineedit(centralwidget); pdfpathlineedit->setobjectname(qstring::fromutf8("pdfpathlineedit")); gridlayout->addwidget(pdfpathlineedit, 0, 0, 1, 1); findpdfpathbutton = new qpushbutton(centralwidget); findpdfpathbutton->setobjectname(qstring::fromutf8("findpdfpathbutton")); gridlayout->addwidget(findpdfpathbutton, 0, 1, 1, 1); photo_list = new photo_list(centralwidget); photo_list->setobjectname(qstring::fromutf8("photo_list")); gridlayout->addwidget(photo_list, 1, 0, 1, 2); gridlayout_2->addlayout(gridlayout, 0, 0, 1, 1); cpdfa->setcentralwidget(centralwidget); toolbar = new qtoolbar(cpdfa); toolbar->setobjectname(qstring::fromutf8("toolbar")); cpdfa->addtoolbar(qt::toptoolbararea, toolbar); menubar = new qmenubar(cpdfa); menubar->setobjectname(qstring::fromutf8("menubar")); menubar->setgeometry(qrect(0, 0, 386, 21)); menu = new qmenu(menubar); menu->setobjectname(qstring::fromutf8("menu")); menu_2 = new qmenu(menubar); menu_2->setobjectname(qstring::fromutf8("menu_2")); cpdfa->setmenubar(menubar); toolbar->addaction(createpdfaction); //!!(*) toolbar->addseparator(); menubar->addaction(menu->menuaction()); menubar->addaction(menu_2->menuaction()); menu->addseparator(); menu_2->addaction(createpdfaction); //!!(*) retranslateui(cpdfa); qmetaobject::connectslotsbyname(cpdfa); } // setupui
i guess using qt creator , designing forms separately form editor.
your problem acutally want class a
(a "larger" widget comprises subobjects) access members in namespace of subobject b
(your photo_list widget).
to this,
move inclusion
"ui_b.h"
b.cpp
b.h
inside
b.h
make private memeberui::b *ui;
public (or can havea
,b
become friends)after including
"b.h"
, having subobject pointer*b
, can callb->ui->actionxxx
ina
access memebers ofb
, sinceb->ui
points namespace includes memebers createdb.ui
file (which turn out inside"ui_b.h"
)
Comments
Post a Comment