Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QTableView QCheckBox QComboBox
How can I
display QCheckBox in the first Column of the QTableView, and QComboBox in several other columns.
get the signal from those QCheckBox and QComboBoxes
Thanks in advance
andre last edited by
Views display checkboxes if the model has the userCheckable flag set, and the model returns valid data for the Qt::CheckStateRole.
To use a combo box as your editor, you will need to set an appropriate QItemDelegate subclass that creates a combobox as the editor widget.
The model will give you a generic dataChanged() signal if the data is modified. Depending your your model, you may get more specific signals from there.
thanks a lot, if the users edit,check or select any item from the GUI, can that dataChanged() signal be emit automatically? In my perspective, model is different with view.
giesbert last edited by
If you create your own custom model, YOU must take care of signals like dataChanged etc.
To get more info on that, read "an editable model":http://doc.qt.nokia.com/4.7/model-view-programming.html#an-editable-model
QComboBoxes has already been displayed, but only double click the cells, the comboboxes will appear, I want those comboboxes appear as the tableview is displayed, how can I do for that, thanks in advance
andre last edited by
That is how delegates work. You can set a widget for a table cell using setCellWidget, but it will not be very performant for larger data sets, and it goes against the grain of model view programming a bit.
octal last edited by
Yes, the editor is created when the user starts editing the cell.
If you want your QComboBox to appear all the time, I guess you'll have to reimplement the paint method of your delegate and draw the QComboBox by yourself. See "QStyle::drawComplexControl":http://doc.qt.nokia.com/latest/qstyle.html#drawComplexControl
goetz last edited by
There's a wiki article "Combo Boxes in Item Views":http://developer.qt.nokia.com/wiki/Combo_Boxes_in_Item_Views that shows you how to create a [[Doc:QStyledItemDelegate]] subclass for that task.