问题描述
我创建了一个按钮“发布按钮”,每次我点击这个按钮时,它都会创建一个带有一些按钮的新小部件,现在我想将动作监听器放到在每个新小部件中创建的动态按钮上 这个关于我的发布按钮如何工作的代码点击它 :
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),ui(new Ui::MainWindow)
{
QObject::connect(
ui->publishbuttontimeline_2,&QPushButton::clicked,this,&MainWindow::onAddWidget);
}
这是我的构造函数,它将发布按钮与创建新小部件及其按钮的方法连接起来
void MainWindow::onAddWidget()
{
//define BoxLayout and each post block
QVBoxLayout*Layout=qobject_cast<QVBoxLayout*>(ui->scrollareapoststimeline->layout());
QWidget*postblock=new QWidget();
QBoxLayout*Boxlayout=new QBoxLayout(QBoxLayout::TopToBottom,postblock);
QPushButton *commentbutton=new QPushButton("comment");
Boxlayout->insertWidget(0,commentbutton);
;
postblock->setLayout(Boxlayout);
//push the Boxlayout which have the post components to the QVBox of the scrollview
Layout->insertWidget(0,postblock);
}
现在我只想对“评论按钮”进行操作以在单击它时打开新的小部件 我怎么能用qt做到这一点,或者如果我想制作另一个按钮来删除所有“postblock”,我可以在插槽中使用什么代码
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)