• 5752阅读
  • 1回复

[原创]QMenu圆角经验分享(非重绘) [复制链接]

上一主题 下一主题
离线pahxgh2000
 
只看楼主 倒序阅读 楼主  发表于: 2011-10-14
mainwindow.cpp
void 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;" >

离线jorneyr

只看该作者 1楼 发表于: 2011-10-15
非常不错
快速回复
限100 字节
 
上一个 下一个