The architecture of the model view is not designed to insert widgets into different cells, but you can draw a button inside the cell.
The differences are as follows:
- It will only be a button drawing
- Without additional work (perhaps quite a lot of additional work), the button will not be highlighted when you hover over
- Due to # 1 above, you cannot use signals and slots
So here is how to do it:
Subclass QAbstractItemDelegate (or QStyledItemDelegate ) and implement the paint() method. To draw a button control (or any other control, for that matter), you need to use the style or method of QStylePainter::drawControl() :
class PushButtonDelegate : public QAbstractItemDelegate { // TODO: handle public, private, etc. QAbstractItemView *view; public PushButtonDelegate(QAbstractItemView* view) { this->view = view; } void PushButtonDelegate::paint( QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { // assuming this delegate is only registered for the correct column/row QStylePainter stylePainter(view); // OR: stylePainter(painter->device) stylePainter->drawControl(QStyle::CE_PushButton, option); // OR: view->style()->drawControl(QStyle::CE_PushButton, option, painter, view); // OR: QApplication::style()->drawControl(/* params as above */); } }
Since the delegate keeps you within the viewing area of ββthe model, use signals of representations of choices and changes to pop up your information window.
Kaleb pederson
source share