[Interest] Change QCheckBox to QPushButton in a QTableView

Jason H jhihn at gmx.com
Thu Dec 7 00:21:41 CET 2017


I have a model, a few columns of which are supposed to be QPushButtons. 
I've got it working with checkboxes just fine, and I can get the QPushButtons to display while editing. 
But I want to display the checkable QPushButton reflecting it's checked state to be displayed all the time, not just when editing.

I looked at the stars delegate example, but that's got some rudimentary painting. 
I found the ProgressBar example in QAbstractItemDelegate, but that didn't worl

void ButtonDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
	if (index.column() == 0) {
		QStyleOptionButton button;
		button.text = _text;
		QApplication::style()->drawControl(QStyle::CE_PushButton, &button, painter);
	} else
		QStyledItemDelegate::paint(painter, option, index);
}

QSize ButtonDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const {
	return QSize(50,10);
}

But all I got out of it was a black pixel in the first cell. 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2017-12-06 at 6.17.03 PM.png
Type: image/png
Size: 7049 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20171207/b3a4d3f5/attachment.png>


More information about the Interest mailing list