QListWidget *list=new QListWidget;
QListWidgetItem *item=new QListWidgetItem(list,0);
item->setSizeHint(QSize(100,100));
QWidget *w = new QWidget(list);
QHBoxLayout *layout=new QHBoxLayout(w);
QPushButton *pushButton=new QPushButton(w);
QCheckBox *checkBox=new QCheckBox(w);
layout->addWidget(checkBox);
layout->addWidget(pushButton);
w->setLayout(layout);
w->show();
list->setItemWidget(item,w);
list->show();
QListWidgetItem *item=new QListWidgetItem(list,0);
item->setSizeHint(QSize(100,100));
QWidget *w = new QWidget(list);
QHBoxLayout *layout=new QHBoxLayout(w);
QPushButton *pushButton=new QPushButton(w);
QCheckBox *checkBox=new QCheckBox(w);
layout->addWidget(checkBox);
layout->addWidget(pushButton);
w->setLayout(layout);
w->show();
list->setItemWidget(item,w);
list->show();
实现了在QListWidgetItem中添加按钮和CheckBox的功能
本文介绍如何在QListWidgetItem中嵌入QPushButton和QCheckBox等控件,并展示了具体的实现代码。通过设置尺寸提示和使用QWidget及布局管理器,可以灵活地在列表项中放置自定义的GUI元素。

5万+

被折叠的 条评论
为什么被折叠?



