QTreeView的Item添加QProgressBar时间:2022-06-04 09:06:04 原理请查qt 的帮助 直接上代码: #include <QApplication>#include <QLineEdit>#include <qDebug>#include <QTime>#include <QTreeWidget>#include <QStringList>#include <QItemDelegate>#include <QProgressBar>class ImageDelegate : public QItemDelegate{public: ImageDelegate(QObject *parent = 0):QItemDelegate(parent){}; QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,const QModelIndex &index) const{QProgressBar *progress = new QProgressBar(parent);progress->setValue(20);return progress;};};int main(int argc, char *argv[]) { QApplication a(argc, argv);QTreeWidget tree;tree.setColumnCount(1);tree.setHeaderLabels(QStringList() << "colum");tree.setItemDelegate(new ImageDelegate(&tree));QTreeWidgetItem *item1 = new QTreeWidgetItem(&tree);tree.openPersistentEditor(item1);QTreeWidgetItem *item2 = new QTreeWidgetItem(&tree);item2->setText(0, "aaaa");tree.show(); return a.exec();} 版权声明 本文为原创作品,请尊重作者的劳动成果。转载必须保持文章完整性,并以超链接形式注明原始作者“ tingsking18 ”和 主站点 地址,方便其他朋友提问和指正。