# # ifndef DELETETOOLBUTTONDELEGATE_H
# define DELETETOOLBUTTONDELEGATE_H
# include & lt; QObject>
# include & lt; QWidget>
# include & lt; QItemDelegate>
# include & lt; QMap>
# include & lt; QStyleOptionButton>
# include & lt; QModelIndex>
The class DeleteToolButtonDelegate: public QItemDelegate
{
Q_OBJECT
Public:
DeleteToolButtonDelegate (parent QObject *=0);
//custom broker component must inherit the following four function
//create edit component
QWidget * createEditor (QWidget * parent, const QStyleOptionViewItem & amp; Option,
Const QModelIndex & amp; The index) const Q_DECL_OVERRIDE;
//get data from the data model, show to the agent component
Void setEditorData (QWidget * editor, const QModelIndex & amp; The index) const Q_DECL_OVERRIDE;
//the broker component data, save the data model
Void setModelData (QWidget * editor, QAbstractItemModel * model,
Const QModelIndex & amp; The index) const Q_DECL_OVERRIDE;
//update agent edit component size
Void updateEditorGeometry (QWidget * editor, const QStyleOptionViewItem & amp; Option,
Const QModelIndex & amp; The index) const Q_DECL_OVERRIDE;
Void paint (QPainter * painter, const QStyleOptionViewItem & amp; Option,
Const QModelIndex & amp; The index) const Q_DECL_OVERRIDE;
Private:
QMap
Signals:
Void deleteCommodityData () const;
};
# endif//DELETETOOLBUTTONDELEGATE_H
Void DeleteToolButtonDelegate: : paint (QPainter * painter, const QStyleOptionViewItem & amp; Option, const QModelIndex & amp; Const index)
{
QStyleOptionButton * button=m_btns. Value (index);
if (! Button) {
The button=new QStyleOptionButton ();
The button - & gt; The rect=option. The rect. Adjusted (0, 0, 0, 0);
//button - & gt; The rect=QRect (option. The rect. Left (), the option. The rect. The top (), the option. The rect. The width (), the option. The rect. Height ());
//button - & gt; Text="X";
The button - & gt; The state |=QStyle: : State_Enabled;
The button - & gt; Icon=QIcon (" :/Image/sc. The PNG ");
The button - & gt; IconSize=QSize (option. The rect. Width (), the option. The rect. Height ());
(const_cast & lt; DeleteToolButtonDelegate * & gt; (this)) - & gt; M_btns. Insert (index, button);
}
Painter - & gt; Save ();
If (option. The state & amp; QStyle: : State_Selected) {//highlighting selected
Painter - & gt; FillRect (option. The rect option. The palette. Highlight ());
}
Painter - & gt; Restore ();
QApplication: : style () - & gt; DrawControl (QStyle: : CE_PushButton, button, painter);
}
CodePudding user response:
CodePudding user response:
Is to remove the small icon, not with sliding block movementCodePudding user response:
Thank you?? ,,