当前位置:网站首页>Write a pure handwritten QT Hello World

Write a pure handwritten QT Hello World

2022-07-08 01:28:00 bin elf

 

Realization effect : Empty item


  Then add the file in the project file

 

  Realize the compilation of window and button controls

#include <QApplication>
#include <QWidget> // Reference header file   Window file base class 

#include <QPushButton> // Button controls 

int main(int argc, char *argv[])
{
    // Objects with and only one application class --- Even if there are many windows 
    QApplication a(argc, argv);
    // Create a blank window 
    QWidget w;
    w.setWindowTitle(" Window for Yang ");// Set title 
    // Show 
    w.show();

    // Create button 
    QPushButton b;
    b.setText(" Yang's exclusive button ");// Give the button facility content 
    b.show();// Give space that shows 
    /* If you do not specify a parent object   Objects and objects ( Windows and windows ) It doesn't matter. , It's independent 
    *a Appoint b For its parent   amount to a stay b On ( The son is above the father )
    * So this case needs to specify that the window is the parent object   Buttons are sub objects   There are two ways 
    *    1)setParent
    *    2) Constructor arguments 
    * Benefits of specifying a parent , You just need the parent object to display   The sub objects above are automatically displayed */
    return a.exec();

}

There are two windows   

 

 

  Realize a window display

 

 

#include <QApplication>

#include <QWidget> // Reference header file   Window file base class 

#include <QPushButton> // Button controls 
int main(int argc, char *argv[])
{
    // Objects with and only one application class --- Even if there are many windows 
    QApplication a(argc, argv);

    // Create a blank window 
    QWidget w;
    w.setWindowTitle(" Window for ");// Set title 

#include <QApplication>

#include <QWidget> // Reference header file   Window file base class 

#include <QPushButton> // Button controls 
int main(int argc, char *argv[])
{
    // Objects with and only one application class --- Even if there are many windows 
    QApplication a(argc, argv);

    // Create a blank window 
    QWidget w;
    w.setWindowTitle(" Window for younger sister Yang ");// Set title 


    // Create button 1
    QPushButton b;
    b.setText(" Yang's exclusive button ");// Give the button facility content 
    b.setParent(&w); // Specify the husband object   It is displayed in the upper left corner   The display effect is not good 
    // Change effect 
    b.move(100,100);// Moving pixels 

    // Create button 2
    QPushButton b1(&w); // Constructor arguments   Specify the parent object 
    b1.setText("abc");// Give the button facility content 


    w.show();// Give space that shows 
    /* If you do not specify a parent object   Objects and objects ( Windows and windows ) It doesn't matter. , It's independent 
    *a Appoint b For its parent   amount to a stay b On ( The son is above the father )
    * So this case needs to specify that the window is the parent object   Buttons are sub objects   There are two ways 
    *    1)setParent
    *    2) Constructor arguments 
    * Benefits of specifying a parent , You just need the parent object to display   The sub objects above are automatically displayed */

    return a.exec();

}

    // Create button 1
    QPushButton b;
    b.setText(" Yang's exclusive button ");// Give the button facility content 
    b.setParent(&w); // Specify the husband object   It is displayed in the upper left corner   The display effect is not good 
    // Change effect 
    b.move(100,100);// Moving pixels 

    // Create button 2
    QPushButton b1(&w); // Constructor arguments   Specify the parent object 
    b1.setText("abc");// Give the button facility content 


    w.show();// Give space that shows 
    /* If you do not specify a parent object   Objects and objects ( Windows and windows ) It doesn't matter. , It's independent 
    *a Appoint b For its parent   amount to a stay b On ( The son is above the father )
    * So this case needs to specify that the window is the parent object   Buttons are sub objects   There are two ways 
    *    1)setParent
    *    2) Constructor arguments 
    * Benefits of specifying a parent , You just need the parent object to display   The sub objects above are automatically displayed */

    return a.exec();

}

 

 

 

 

原网站

版权声明
本文为[bin elf]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/189/202207072328328103.html