button.state = QStyle::State_Sunken;
button.state = (QStyle::State_Sunken | QStyle::State_Enabled);
void paint(QPainter *painter, const QStyleOptionViewItem &option,const QModelIndex &index) const{ const packetModel * model_; model_ = static_cast<const packetModel*>(index.model()); if (/*index.column() == 1 || */index.column() == 1) { // qDebug() << option.state; QStyleOptionButton but; but.rect = option.rect; but.text = QString::number(777); if (model_->dataCell(index.row(), index.column()) > 0) but.state = QStyle::State_Enabled; else but.state = QStyle::State_Sunken ; QApplication::style()->drawControl(QStyle::CE_PushButton,&but, painter); } else QStyledItemDelegate::paint(painter, option, index);};
C++ (Qt) QStyleOptionButton but; if( QWidget* w = dynamic_cast< QWidget* >( painter->device() ) ) but.initFrom( w ); but.rect = option.rect; but.text = QString::number(777); if (model_->dataCell(index.row(), index.column()) <= 0) but.state |= QStyle::State_Sunken ; QApplication::style()->drawControl(QStyle::CE_PushButton,&but, painter);
C++ (Qt) QStyleOptionButton but; but.rect = option.rect; but.text = QString::number(777); if( QWidget* w = dynamic_cast< QWidget* >( painter->device() ) ) { if( w->isEnabled() ) but.state |= QStyle::State_Enabled; if( w->window()->isActiveWindow() ) but.state |= QStyle::State_Active; if( QRect( w->mapToGlobal( rect.topLeft() ), rect.size() ).contains( QCursor::pos() ) ) { but.state |= QStyle::State_MouseOver; if (model_->dataCell(index.row(), index.column()) <= 0) { but.state |= QStyle::State_Sunken; } if( wt->hasFocus() ) but.state |= QStyle::State_HasFocus; } } else { but.state |= QStyle::State_Enabled; } QApplication::style()->drawControl(QStyle::CE_PushButton,&but, painter);
C++ (Qt)but.state = but.state | QStyle::State_Sunken;
QStyleOptionButton but; but.rect = option.rect; but.text = QString::number(777); if( QWidget* w = dynamic_cast< QWidget* >( painter->device() ) ) { if( w->isEnabled() ) but.state |= QStyle::State_Enabled; if( w->window()->isActiveWindow() ) but.state |= QStyle::State_Active; if( QRect( w->mapToGlobal( but.rect.topLeft() ), but.rect.size() ).contains( QCursor::pos() ) ) { but.state |= QStyle::State_MouseOver; if (model_->dataCell(index.row(), index.column()) <= 0) { but.state |= QStyle::State_Sunken; } if( w->hasFocus() ) but.state |= QStyle::State_HasFocus; } } else { but.state |= QStyle::State_Enabled; } QApplication::style()->drawControl(QStyle::CE_PushButton,&but, painter);