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をペイントして画像を取得する
問題を簡単に説明すると、この質問を閉じることができます。 – eyllanesc
私は誤解をおかけして申し訳ありません... Qtのスタイルシートを使用して、メニュー項目を選択して、QMenuのactionRectを取得する必要があります。 –
あなたの質問を編集してそこに追加してください(https://stackoverflow.com/posts/44298888/edit)。 – eyllanesc