void
JQLineTypeMenu::paintEvent(
)
{
//draw the items that need updating..
foreach
( QAction* action, actions
() ) {
QRect adjustedActionRect
= actionGeometry
(action
);
if ( !event->rect().intersects(adjustedActionRect) )
continue;
//set the clip region to be extra safe (and adjust for the scrollers)
QRegion adjustedActionReg
(adjustedActionRect
);
emptyArea -= adjustedActionReg;
p.setClipRegion(adjustedActionReg);
initStyleOption(&opt, action);
opt.rect = adjustedActionRect;
drawMenuItem(&opt, &p, action);
}
...
}
void
JQLineTypeMenu::drawMenuItem(
)
{
bool act
= opt
->state
& QStyle::State_Selected;
p->fillRect(opt->rect, fill);
QPen linePen
(static_cast<Qt
::PenStyle>
(action
->data
().
toInt()));
linePen.setWidth(3);
linePen.
setBrush(opt
->palette.
brush(act ?
QPalette::HighlightedText : QPalette::ButtonText));
p->setPen(linePen);
p->drawLine(opt->rect.left(), opt->rect.center().y(), opt->rect.right(), opt->rect.center().y());
}
void
JQLineTypeMenu::paintEvent(
QPaintEvent* event
)
{
QPainter p(this);
QRegion emptyArea = QRegion(rect());
//draw the items that need updating..
foreach ( QAction* action, actions() )
{
QRect adjustedActionRect = actionGeometry(action);
if ( !event->rect().intersects(adjustedActionRect) )
continue;
//set the clip region to be extra safe (and adjust for the scrollers)
QRegion adjustedActionReg(adjustedActionRect);
emptyArea -= adjustedActionReg;
p.setClipRegion(adjustedActionReg);
QStyleOptionMenuItem opt;
initStyleOption(&opt, action);
opt.rect = adjustedActionRect;
drawMenuItem(&opt, &p, action);
}
...
}
void
JQLineTypeMenu::drawMenuItem(
const QStyleOptionMenuItem* opt,
QPainter* p,
const QAction* action
)
{
bool act = opt->state & QStyle::State_Selected;
QBrush fill = opt->palette.brush(act ? QPalette::Highlight : QPalette::Button);
p->fillRect(opt->rect, fill);
QPen linePen(static_cast<Qt::PenStyle>(action->data().toInt()));
linePen.setWidth(3);
linePen.setBrush(opt->palette.brush(act ? QPalette::HighlightedText : QPalette::ButtonText));
p->setPen(linePen);
p->drawLine(opt->rect.left(), opt->rect.center().y(), opt->rect.right(), opt->rect.center().y());
}
To copy to clipboard, switch view to plain text mode
The various actions in the menu held the different pen styles (using
Bookmarks