The first Qt program (small excitement)

Now write it from scratch written, not ready-made framework, create a blank file.

 Code written in the first sentence, plus module, a graphical interface can be programmed.

Qt += widgets

Add a new file

 File name suffix must be .cpp .

Now start writing code

 

 

 Run get a window with a title. --Nothing at all.

 

Simply add a button

 

 Ah, really good, you can! The results of it. . . .

 

 What! ! ! This button drifted! ! !

/ * 
     * If no parent object, object and the object (a window and a window) without contact, independent 
     * a b to its specified parent object A is placed above b 
     * specified parent object, there are two ways: 
     * 1) the setParent 
     * 2) pass through the reference constructor 
     * designated parent, the parent object displayed just above the child object is automatically displayed 
    * /
 1 #include<QApplication>
 2 #include<QWidget>  //窗口控件基类
 3 #include <QPushButton>
 4 
 5 int main(int argc,char **argv)
 6 {
 7     QApplication app(argc,argv);
 8 
 9     QWidget w;
10     w.setWindowTitle("我要学Qt!!!");
11 
12     QPushButton b;
13     b.setText("start");  //给按钮设置内容
14     b.setParent(&w);
15 
16     w.show();
17     app.exec();
18     return 0;
19 }

 

 这里要注意的是setParent函数的参数是地址,所以记得&。

 Qt是有坐标系统的,到后面慢慢学吧!!!奥里给!!!

先简单的了解下

窗口左上角是(0,0).

单位是像素。

就知道这么多了!

第一种方式setParent函数

 

 

 

第二种方式构造函数传参

 

 

 好吧!最终得到了一个僵尸窗口。哈哈哈哈。。。。。

Guess you like

Origin www.cnblogs.com/wlyperfect/p/12391543.html