[Interest] Change QCheckBox to QPushButton in a QTableView

Tony Rietwyk tony at rightsoft.com.au
Thu Dec 7 02:02:18 CET 2017


Hi Jason,

You'll have to initialise quite a bit more in the QStyleOptionButton 
button than just the text - especially the inherited rect member.   
Maybe QStyleOption.initFrom can help, or create an override class on 
QPushButton to expose its initStyleOption.

Hope that helps, Tony


On 7/12/2017 10:21 AM, Jason H wrote:
> 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.
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20171207/6e32a375/attachment.html>


More information about the Interest mailing list