PDA

View Full Version : QMenu round corners



medved6
16th September 2010, 07:44
Hi everybody

I'm trying to make round corners for contect menu.



qApp->setStyleSheet("\
QMenu {\
background-color: black;\
color: white;\
font-family: Bodoni MT;\
font-size: 18px;\
border-radius: 10px;\
border: 1px solid rgb(110, 110, 110);\
}\
QMenu::item{\
padding-top: 4px;\
padding-left: 5px;\
padding-right: 15px;\
padding-bottom: 4px;\
}\
QMenu::item:selected {\
background: rgb(40, 40, 40);\
}");



But I can still see the rectangular corner.
Any Idea?

e8johan
16th September 2010, 14:07
From your code, it augth to work. When do you create the context menu, and how do you show it? Can you apply the style sheet directly to that QMenu object?

medved6
17th September 2010, 03:24
Here is part of the code



void GraphicsView::contextMenuEvent ( QContextMenuEvent * event )
{
QAction cm_exit("Exit",0);
QAction cm_fitinview("Fit in View",0);

QMenu menu;


menu.addAction(&cm_fitinview);
menu.addAction(&cm_exit);

QAction* act = menu.exec(QCursor::pos());
....

}

If I apply style sheet directrly it gives same result( just tried)
I just want to use same stylesheet for all menus in app.

pervlad
17th September 2010, 08:50
I just took the glance at your style-sheet. I am not sure, but it seems to me that many of the style-sheet properties you trying to use are not supported in Qt. There is a list of supported style-sheet properties in Qt documentation. Try find it and check it out.

medved6
17th September 2010, 08:55
I did. Did not successeded.
This is why I'm here :)

reb_elba
17th September 2010, 11:58
Hi,

test this:


int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(NBrowser);

QApplication app(argc, argv);

app.setStyleSheet("\
QMenu {\
background-color: black;\
color: white;\
font-family: Bodoni MT;\
font-size: 18px;\
border-radius: 10px;\
border: 1px solid rgb(110, 110, 110);\
}\
QMenu::item{\
padding-top: 4px;\
padding-left: 5px;\
padding-right: 15px;\
padding-bottom: 4px;\
}\
QMenu::item:selected {\
background: rgb(40, 40, 40);\
}");
MainWindow mainWin;
mainWin.show();
return app.exec();
}

it works on MAC
with your stylesheet
https://files.me.com/relbarnoussi/y3qwzg

without your stylesheet
https://files.me.com/relbarnoussi/8ddkcq

hth,
Ralf

medved6
17th September 2010, 16:31
Do yoy see some black corners out of gray radius on the first scrrenshort? I wnat to avoid that.

reb_elba
17th September 2010, 21:13
sorry i've misunderstood. I thought it does not display your css.
I've played a bit with your css, but the black corners still remain.

what's about using a black background-image with 10px radius like: background-image: url(:/images/blackradius.png); and background-color: transparent?
i try it tomorrow...

medved6
17th September 2010, 21:18
sounds like good idea. I'll try and let you know.

wysota
17th September 2010, 22:33
I don't think what you want will work with stylesheets because QMenu is a top-level widget and thus it is rectangular. If you want to round the borders, I'm afraid you will have to use QWidget::setMask() or set the translucency attribute and make sure only the part you want is painted (which you probably won't be able to do with stylesheets).