获取QMenu的ActionRect油漆的图像
问题描述:
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油漆的图像
答
尝试this-> actionGeometry(QAction *),它应该返回正确的QRect。 我在我的一个程序中使用了它,它工作得很好。
你可以简单描述一下你的问题,如果你这么说可能会关闭这个问题。 – eyllanesc
抱歉误会....我需要获取QMenu的paintRect选择的菜单项目使用Qt的样式表。 –
请[编辑](https://*.com/posts/44298888/edit)您的问题,并将其添加到那里 – eyllanesc