Reputation: 41
QPainter p(this);
for (int i = 0; i < this->actions().count(); ++i)
{
QAction *action = this->actions().at(i);
QRect actionRect = ...........
QStyleOptionMenuItem opt;
initStyleOption(&opt, action);
opt.rect = actionRect;
QString strPicPath="/h/downloads/tableviewenabledBackGroundImageId.jpg";
QPixmap pic(strPicPath);
pic=pic.scaled(opt.rect.size());
opt.palette.setBrush(QPalette::Background,QBrush(pic));
p.fillRect(opt.rect,opt.palette.background());
style()->drawControl(QStyle::CE_MenuItem, &opt, &p, this);
}
i need get actionRect of QMenu for paint selected menu Item with out Using Qt's Stylesheet. thanks in advance
Upvotes: 0
Views: 349
Reputation: 1
Try this->actionGeometry(QAction*), which should return the correct QRect. I used this in one of my programs, where it worked quite well.
Upvotes: 0