mainwindow.cppvoid MainWindow::on_Library_clicked(){
QMenu menu(
this);
QMenu *LanguageMenu
=
menu.addMenu(tr(
"&Language"));
QAction *EnMenu
=
new QAction(tr(
"&English"),
this);
QAction *ZhCnMenu
=
new QAction(tr(
"Chinese &Simple"),
this);
LanguageMenu->addAction(EnMenu);
LanguageMenu->addAction(ZhCnMenu);
QMenu *Skin
=
menu.addMenu(tr(
"&Skin"));
QAction *WBAction
=
new QAction(tr(
"&White and Blue"),
this);
QAction *OtherAction
=
new QAction(tr(
"&Other"),
this);
Skin->addAction(WBAction);
Skin->addAction(OtherAction);
QPainterPath path;
QRectF rect
=
QRectF(
0,
0,menu.
sizeHint().width(),menu.
sizeHint().height());
path.addRoundedRect(rect,
5,
5);
QPolygon polygon=
path.toFillPolygon().toPolygon();
QRegion region(polygon);
menu.setMask(region);
QPoint pos;
pos.setX(
0);
pos.setY(-menu.
sizeHint().height());
menu.exec(
ui->
Library->mapToGlobal(pos));}
library.qssQMenu
{border-radius:
5px;border:
1px
solid
rgb(110,
110,
110);}这是我在做QMenu圆角处理过程中写的代码,使用遮罩做的,
没有用到重构,有些瑕疵的是左下和左上角有些白边,这里如果没有使用Qss做圆角边可以避免瑕疵,但是就没有边了,而且圆角要超过6,否则也会出现瑕疵,期待高手解决。下面附上效果图
window.open('http://www.qtcn.org/bbs/attachment/Mon_1110/17_122425_331376dcbb00af4.jpg?4');" style="max-width:700px;max-height:700px;" onload="if(is_ie6&&this.offsetWidth>700)this.width=700;" >