2017-06-01 56 views
0
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); 
} 

我需要得到QMenu的actionRect油漆選擇的菜單項與出使用Qt的樣式表。 在此先感謝獲取QMenu的ActionRect油漆的圖像

+0

你可以簡單描述一下你的問題,如果你這麼說可能會關閉這個問題。 – eyllanesc

+0

抱歉誤會....我需要獲取QMenu的paintRect選擇的菜單項目使用Qt的樣式表。 –

+0

請[編輯](https://stackoverflow.com/posts/44298888/edit)您的問題,並將其添加到那裏 – eyllanesc

回答

0

嘗試this-> actionGeometry(QAction *),它應該返回正確的QRect。 我在我的一個程序中使用了它,它工作得很好。