QStyledItemDelegate - Update paint after state change
Solved
General and Desktop
-
I have delegate button that I will be changing its state through a function like this:
void MyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionButton button; QRect r = option.rect;//getting the rect of the cell int x,y,w,h; x = r.center().x() - 10;//the X coordinate y = r.top();//the Y coordinate w = 20;//button width h = 20;//button height button.rect = QRect(x,y,w,h); button.text = ""; if(isEnabled) button.state = QStyle::State_Enabled; else button.state &= ~QStyle::State_Enabled; QApplication::style()->drawControl( QStyle::CE_PushButton, &button, painter); QItemDelegate::paint(painter, option, index); } void MyDelegate::setEnable(bool enabled) { isEnabled = enabled; }
After calling
setEnable()
the state doesn't change(visually) immediately like I desire it to. I was hoping for aupdate()
-like function but I found no such.
So I am wondering how to do that.