qt界面中用纯代码来new一个pushbutton,不使用拖拽

tech2025-11-16  4

1、首先还是新建一个界面出来,然后就是直接在构造函数中上代码,如下:

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); QPushButton *pushbutton2 = new QPushButton(this); pushbutton2->move(100,200); pushbutton2->setObjectName(QString::fromUtf8("123")); pushbutton2->setText("hello world"); }

2、最后编译如下:

 

最新回复(0)