Have a look Qt Layout management mechanism and Qt Control for , Just put it all together , Wrote a simple Qt code
What's more, I want to ask if there is an introduction Qt Procedures such as the implementation of calculator type can practice a hand , Consolidate your knowledge !
main.cpp
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style="
color:#000080;">#include</span><span style=" color:#c0c0c0;"> </span><span
style=" color:#008000;">"mainwindow.h"</span> #include <QApplication> int main(
int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show();
return a.exec(); }
mainwindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include
<QMenu> #include<QMenuBar> #include<QAction> #include<QToolBar> #include
<QDialog> #include<QPushButton> #include<QVBoxLayout> #include<QHBoxLayout>
#include<QGridLayout> #include<QLineEdit> #include<QLabel> class MainWindow :
public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~
MainWindow(); protected: QMenu *File; QMenu *Edit; QMenu *Window; QMenu *Help;
QMenuBar *total; QAction *open; QAction *save; QAction *cancel; QAction *chat;
QToolBar *Tool1; QToolBar *Tool2; public slots: void openclicked();// Define slot function };
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow
(parent) { this->setFixedSize(400,300); open=new QAction(QIcon(":/image/clean"),
"open",this); open->setStatusTip("you will open a messagebox"); statusBar();
// It is a function of a class, so it can be called directly , show the status bar save=new QAction(QIcon(":/image/download"),"save",this);
cancel=new QAction(QIcon(":/image/alert"),"cancel",this); chat=new QAction(QIcon
(":/image/chat"),"chat",this); File=new QMenu(" File ");// Add action to menu bar File
->addAction(open); Edit=new QMenu(" Edit "); Edit->addAction(chat); Window=new
QMenu(" Window "); Window->addAction(cancel); Help=new QMenu(" Help "); Help
->addAction(save); menuBar()->addMenu(File); // Add a menu item to the main window menuBar()->addMenu(Edit
); menuBar()->addMenu(Window); menuBar()->addMenu(Help); Tool1=new QToolBar(this
);// Add actions to the toolbar Tool1->addAction(open); Tool1->addAction(cancel); Tool2=new
QToolBar(this); Tool2->addAction(save); Tool2->addAction(chat); addToolBar(Qt::
TopToolBarArea,Tool1);// Add these two toolbars to the window addToolBar(Qt::TopToolBarArea,Tool2);
connect(open,SIGNAL(triggered()),this,SLOT(openclicked())); } class dialog:
public QDialog { public: QPushButton *button1; QPushButton *button2; QLineEdit *
lineidt; QLabel *label; QGridLayout *gridlayout; dialog()// Constructor { this
->setFixedSize(600,400); button1=new QPushButton("choose"); button2=new
QPushButton("quit"); label=new QLabel("input data"); lineidt=new QLineEdit("");
gridlayout=new QGridLayout(this); gridlayout->addWidget(label,0,0); gridlayout
->addWidget(lineidt,0,1); gridlayout->addWidget(button1,1,0); gridlayout
->addWidget(button2,1,1); connect(button2,SIGNAL(clicked()),this,SLOT(close()));
setLayout(gridlayout); } ~dialog() { } }; void MainWindow::openclicked() {
dialog a; a.exec(); } MainWindow::~MainWindow() { }
Technology
Daily Recommendation