简体   繁体   English

在 Qt5 中的 QWidget 中添加一个新按钮

[英]add a new button in a QWidget in Qt5

I am trying to add a new QPushButton to a QWidget, but it doesn't seem to have an addWiget method.我正在尝试向 QWidget 添加一个新的 QPushButton,但它似乎没有addWiget方法。

I am using the following code:我正在使用以下代码:

  QWidget *wdg = new QWidget;
  QPushButton *btn=new QPushButton(this);

  btn->setText("text");
  
  wdg->addWidget(btn)

  wdg->show();
  hide();

the 6th line is giving an error第 6 行给出错误

You can pass QWidget as parent to QPushButton.您可以将 QWidget 作为父级传递给 QPushButton。

QWidget *wdg = new QWidget;
QPushButton *btn=new QPushButton(wdg);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM