QTableView / QTableWidget中类似Ktorrent的小部件

时间:2012-03-13 18:01:23

标签: c++ qt user-interface qt4 qtgui

是否有关于如何将自定义QWidget容器(包括布局,复选框,按钮等其他内容)作为QTableView / QTableWidget中的行放置的文档,如图所示?

我正在浏览ktorrent的源代码以了解如何完成此操作。

非常感谢任何帮助。

Ktorrent configuration widget as a QTableView row

1 个答案:

答案 0 :(得分:1)

使用QTableWiget

void QTableWidget::setCellWidget (int row, int column, QWidget  *widget)

在你的情况下:

class MyWidget : public QWidget {
  // a composite widget with layouts and other stuff
};
setCellWidget(0, 0, new MyWidget);

如果是QTableView,您必须定义自定义委托并为某个列设置(例如):

void QAbstractItemView::setItemDelegateForColumn (int column, QAbstractItemDelegate * delegate)

Check this out以获取表格中的QProgressBar示例