如果自己做网站,外贸网络推广,嘉兴网站设计公司,关键词是指什么QWidget 用来构建简单窗口
QMainWindow 用来构建更复杂的窗口#xff0c;QMainWindow 继承自QWidget#xff0c;在QWidget 的基础上提供了菜单栏、工具栏、状态栏等功能
菜单栏#xff08;QMenuBar#xff09;工具栏#xff08;QToolBar#xff09;状态栏#xff08;Q…QWidget 用来构建简单窗口
QMainWindow 用来构建更复杂的窗口QMainWindow 继承自QWidget在QWidget 的基础上提供了菜单栏、工具栏、状态栏等功能
菜单栏QMenuBar工具栏QToolBar状态栏QStatusBar中央窗口区域setCentralWidget() #include QAction
#include QApplication
#include QMainWindow
#include QMenuBar
#include QMessageBoxclass MyWindow : public QMainWindow {
public:MyWindow(){// 创建菜单栏QMenuBar* menuBar this-menuBar();// 创建菜单QMenu* fileMenu menuBar-addMenu(File);// 创建菜单项QAction* newAction new QAction(New, this);QAction* openAction new QAction(Open, this);QAction* exitAction new QAction(Exit, this);// 将菜单项添加到菜单中fileMenu-addAction(newAction);fileMenu-addAction(openAction);fileMenu-addSeparator(); // 添加分隔符fileMenu-addAction(exitAction);// 连接信号和槽connect(newAction, QAction::triggered, this, MyWindow::newFile);connect(openAction, QAction::triggered, this, MyWindow::openFile);connect(exitAction, QAction::triggered, this, MyWindow::exitApp);}private:void newFile(){QMessageBox::information(this, New File, New file action triggered!);}void openFile(){QMessageBox::information(this, Open File, Open file action triggered!);}void exitApp(){QApplication::quit();}
};int main(int argc, char* argv[])
{QApplication app(argc, argv);MyWindow window;window.resize(800, 600);window.show();return app.exec();
}