PDA

View Full Version : qt pushed icon and widgetbox



giugio
9th November 2012, 10:26
hello.
I wish create a delegate that draw an icon with two state raised and pushed based on the state of the button.
I think to draw a QStyleOptionButton with the icon , but my code don't work.


void CustomItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
/*const QAbstractListModel* model =
static_cast<const QAbstractListModel*>(index.model());
QStandardItem* item = model->item(index.row());*/


QString text = "pipo";
QRect rect = option.rect;

QRect textRect( rect);
textRect.setHeight( 30);
painter->drawText(textRect,text);

QRect buttonRect( rect);
buttonRect.setY(textRect.y()+ 35);
buttonRect.setHeight( 30);
QStyleOptionButton button;
QIcon undoicon = QIcon::fromTheme("edit-undo", QIcon(":/undo.png"));

button.icon = undoicon;
button.iconSize = QSize(32,32);

button.rect = buttonRect;
button.text = text;
button.state = _state | QStyle::State_Enabled;

QApplication::style()->drawControl
(QStyle::CE_PushButton, &button, painter);
}

my goal is to use a widget like the widgetbox desingner but with a pressed /raised icon.
8402
Is possible ?