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 QAbstractListModel* model =
static_cast<const QAbstractListModel*>(index.model());
QStandardItem* item = model->item(index.row());*/
QRect rect
= option.
rect;
textRect.setHeight( 30);
painter->drawText(textRect,text);
buttonRect.setY(textRect.y()+ 35);
buttonRect.setHeight( 30);
button.icon = undoicon;
button.
iconSize = QSize(32,
32);
button.rect = buttonRect;
button.text = text;
button.
state = _state |
QStyle::State_Enabled;
(QStyle::CE_PushButton,
&button, painter
);
}
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);
}
To copy to clipboard, switch view to plain text mode
my goal is to use a widget like the widgetbox desingner but with a pressed /raised icon.
Immagine.jpg
Is possible ?
Bookmarks