2017-06-01 5 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); 
} 

Qtのスタイルシートを使用して、選択したメニューのQMenuのアクションを取得する必要があります。 ありがとうございましたQMenuのActionRectをペイントして画像を取得する

+0

問題を簡単に説明すると、この質問を閉じることができます。 – eyllanesc

+0

私は誤解をおかけして申し訳ありません... Qtのスタイルシートを使用して、メニュー項目を選択して、QMenuのactionRectを取得する必要があります。 –

+0

あなたの質問を編集してそこに追加してください(https://stackoverflow.com/posts/44298888/edit)。 – eyllanesc

答えて

0

これを試してください:正しいQRectを返すべきactionGeometry(QAction *)。 私はこのプログラムを私のプログラムの1つで使いました。

関連する問題