mukthar ali
mukthar ali

Reputation: 41

Get QMenu's ActionRect for paint an image

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

Answers (1)

user8531130
user8531130

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

Related Questions