user interface - Drawing a check mark in Qt -
I am working with simple QTreeView, each line of the tree inherited from one class EditorRow Found is a specific category.
EditorRow These functions are:
Virtual QVariant data (ColumnIndexEnum index, int role = Qt :: DisplayRole) const = 0; Virtual wide setdata (constant queue variant and data, column index number index, int roll = qt :: userroll); Virtual QWidget * getEditor (QWidget * parent) const;
Each line has its own specific widget, which is shown in the right column when selecting that row. When the row is not selected, the data function returns the appropriate value for each row (Fu value which was selected in QComboBox).
But in the case of a row, whose widget is QCheckBox, if the row is not selected, I must draw a check (or uncheck) checkbox.
I have tried to use the role of decoration like this:
if (Qt :: decorative == role) {if (ValueColumn == index) { QStyle * style = QApplication :: style (); QStyleOptionButton opt; Opt.state | = QStyle :: State_Enabled; If (check is ()) opt.state = QStyle :: State_On; Else opt.state = QStyle :: State_Off; Const int index = style-> Pixel Metric (QStyle :: PM_IndicatorWidth, & amp; Options); Const int indicatorHeight = style-> pixel metric (QStyle :: PM_IndicatorHeight, & amp; op); Const int listViewIconSize = indicatorWidth; Const int pixmapWidth = indicatorWidth; Const int pixmapHeight = qMax (indicator hight, see list IconSize); Opt.rect = QRect (0, 0, indicator width, indicator high); QPixmap pixmap = QPixmap (pixmapWidth, pixmapHyight); Pixmap.fill (Qt :: transparent); {Couponer painter (& amp; pixmap); QCheckBox cb; Cb.setLayoutDirection (QT :: RightToLeft); Style- & gt; Attractive (QStay :: PE_IndicatorCheckBox, & amp; Opt, & amp; Painting, & amp; cb;); } Return QIcon (pixmap); }}
This really works, but the icon is always shown, even when the line is selected, I think this decoration is due to the rota.
Do you have any problems how to deal with this problem?
Thank you.
Comments
Post a Comment