qt - Setting the style of QFrame -


i have qframe, titled 'bannerframe' embedded in dialog, other widgets.

i want dynamically change background of frame. if use stylesheet defined in top level dialog (messagedlg), appears correctly, this: -

correct gradient

the stylesheet defined as

#bannerframe {     background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0,                                      stop:0 rgba(195, 40, 9, 255),                                      stop:0.7 rgba(225, 121, 113, 255),                                      stop:1 rgba(237, 154, 152, 255)); } 

however, if remove , add style directly bannerframe widget, gradient doesn't seem work properly: -

bad gradient

the same effect seen, regardless of setting stylesheet in designer, or in code:

qstring style = qstring("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0,\                            stop:0 rgba(%1, %2, %3, 255),\                            stop:1 rgba(%4, %5, %6, 255));").arg(red1).arg(green1).arg(blue1).arg(red2).arg(green2).arg(blue2);  ui->bannerframe->setstylesheet(style); 

so, what's going on here?

why gradient not work correctly around frame's widgets when stylesheet set directly on frame, rather on top-level dialog?

that's because widgets in frame inherit parents stylesheet. see qlabel widget icon having gradient background. add selector limit widgets styles should apply to.

qstring style = qstring("qframe {...}"); 

or

qstring style = qstring("qframe#bannerframe {...}"); 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -