example_g3.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <qapplication.h>
  2. #include <qmenubar.h>
  3. #include <qpopupmenu.h>
  4. #include "example_g3.h"
  5. MyWindow::MyWindow(QWidget *parent, const char *name)
  6. : QWidget(parent, name)
  7. {
  8. setCaption("Main Window");
  9. QPopupMenu *file_popup = new QPopupMenu(this);
  10. file_popup->insertItem("&New", this, SLOT(fileNew()));
  11. file_popup->insertItem("&Open...", this, SLOT(fileOpen()));
  12. file_popup->insertItem("&Save", this, SLOT(fileSave()));
  13. file_popup->insertItem("Save &as...", this, SLOT(fileSaveAs()));
  14. file_popup->insertSeparator();
  15. file_popup->insertItem("&Print", this, SLOT(filePrint()));
  16. file_popup->insertSeparator();
  17. file_popup->insertItem("E&xit", qApp, SLOT(quit()));
  18. QPopupMenu *help_popup = new QPopupMenu(this);
  19. help_popup->insertItem("&About", this, SLOT(helpAbout()));
  20. menu = new QMenuBar(this);
  21. menu->insertItem("&File", file_popup);
  22. menu->insertItem("&?", help_popup);
  23. }
  24. MyWindow::~MyWindow()
  25. {
  26. }
  27. void MyWindow::helloClicked()
  28. {
  29. }
  30. int main(int argc, char **argv)
  31. {
  32. QApplication a(argc, argv);
  33. MyWindow w(0, "main window");
  34. w.setGeometry(10, 10, 200, 150);
  35. a.setMainWidget(&w);
  36. w.show();
  37. return a.exec();
  38. }