开发者

Dynamic Widget List with QPushButton, QComboBox QCheckbox

I'd like to create a list, each row in this list contains:

LineNo | Edit Model  | Model Select | Log enabl | freq      | selection |
1      | QPushButton开发者_StackOverflow中文版 | QComboBox    | QCheckBox | QLineEdit | QLineEdit |
2      | QPushButton | QComboBox    | QCheckBox | QLineEdit | QLineEdit |
3      | QPushButton | QComboBox    | QCheckBox | QLineEdit | QLineEdit |
|             |            |              |          |           |      |
n      | QPushButton | QComboBox    | QCheckBox | QLineEdit | QLineEdit |

This list is dynamic, i have a total of 36 models but only a selection of these should be represented depending on choices that has been made. The user sould be able to regret any earlier choices and redraw this list.

I have been looking at QListView, QTableWidget, Delegates, but i cant seem to find any examples or turorials on how to implement QPushButton into either QListView or QTableWidget. Looking at the documentation of QItemDeligate QPushButton are not among the accepted types.


I believe you're looking for one of the following functions (depending on which view class you're using):

QTableWidget::setCellWidget( int, row, int column, QWidget *widget );
QTreeWidget::setItemWidget( QTreeWidgetItem *item, int column, QWidget *widget );
QListWidget::setItemWidget( QListWidgetItem *item, QWidget *widget );

This will allow you to display an arbitrary widget in the desired location, no mucking with delegates required.

Note that these functions are only available in the "Widget" versions of these views (e.g. QTreeWidget as opposed to QTreeView). However there is a setIndexWidget() function in QAbstractItemView that can be used as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜