我创建了一个按钮“ + add”。我想做的是在同一窗口中单击“ +添加”按钮后创建另一个按钮“编辑”。
是否可以在另一个窗口中创建另一个按钮?我尝试使用此方法,但是它不起作用,我无法理解作为第二个参数应该写什么?
QPushButton::QPushButton(const QString &text, QWidget *parent = nullptr)
仅声明没有初始化的引用,然后调用创建函数并将此按钮引用传递给它。
NOT,用于在函数内部创建引用。
QPushButton *btn = new QPushButton("Click Me", this); //this is parent, give another window/widget address to draw/create it there
btn->setGeometry(100, 200, 150, 50); //set position, width, height
connect(btn, SIGNAL(clicked()), this, SLOT(a_slot())); //make it useful
btn->show();
btn->setText("Push Me"); //change button text later if you want