PDA

View Full Version : How to conrol frame of widgets in a QStatuBar?



high_flyer
22nd April 2006, 13:10
Hi,

I am using a QStatusBar in which I add some widgets (QLabel).
The probem is, that the QLables appear with a line frame around them in the status bar, but I don't want that.
I am sure that it is QSatusBar who is adding the line frame since when creating the QLabel I made sure it is with Qt:NoFrame.
Any idea how I can control this border addition to the widgets in QStatusBar?

Qt4 SUSE10.

Thanks.

jpn
22nd April 2006, 14:01
Yep, the frame seems to be painted by QStatusBar:
Qt-4.1.2/src/gui/widgets/qstatusbar.cpp (549):


style()->drawPrimitive(QStyle::PE_FrameStatusBar, &opt, &p, item->w);


You could create a custom style which doesn't draw the primitive element (QStyle::PE_FrameStatusBar) at all.

high_flyer
22nd April 2006, 14:05
Yes I could...
But I was hoping its possible already through the existing API that maybe I missed...

Thanks.

jpn
22nd April 2006, 14:09
I totally agree this being a bit weird. In my opinion drawing of the status bar widget frames should definitely be optional..

Usability
8th September 2007, 21:17
You do this with Style sheets. You probably have a line like this


QApplication app(argc, argv);

underneath that, add one like this:


app.setStyleSheet("QStatusBar::item { border: 0px solid black }; ");

and those pesky boxes will be gone.

Micawber
6th December 2007, 16:28
I am having the same problem and I tried the style sheet solution suggested and while that does get rid of the frames, it breaks something else.

I have code that dynamically changes the background color of status bar items and these color changes no longer work if I set a style sheet. Any other clues other than creating a custom style? (lots of work, I'm a beginner :eek: )

-Mic

jpn
6th December 2007, 16:45
I have code that dynamically changes the background color of status bar items and these color changes no longer work if I set a style sheet.
How do you do it? May we see the relevant code? Are you using the good old palette approach the change the background color of them? I think you shouldn't mix palettes and style sheets.

Micawber
6th December 2007, 19:06
Yes, I am using QPalette::setPalette()

If this doesn't work with style sheets, any other suggestions on how to remove the frames?

-Mic

jpn
6th December 2007, 19:15
Well, actually I was suggesting that perhaps you should do it all with style sheets. Setting background colors with style sheets is even easier than with palettes.. :)

Micawber
6th December 2007, 19:52
Well would you look at that! I changed my code to set the background via label->setStyleSheet( "background-color: red" ); instead of using the setPalette method and it works!! Cool! :p

Thanks for the suggestion!!!

-Mic

wysota
6th December 2007, 21:12
The whole thing sucks. Someone should file a report on the frame thing... I hate to be forced to use stylesheets. I can understand that some things have to be done by them because the style itself doesn't support changing things (like the red pushbutton syndrom), but I don't think this is the case here.

Micawber
7th December 2007, 14:19
I agree. I don't like the idea of being forced to use style sheets either. Neat idea though, but I would have thought the API to have a suitable method to control this behavior.

I have submitted a bug report. Haven't heard anything yet.

alisami
30th September 2008, 01:19
I came across that when using the style with the following code as mentioned above the widgets are repainted whenever the mouse focus is on and off the corresponding widget. There may be a problem about it. Using the flag QT_FLUSH_PAINT the situation can be observed.


app.setStyleSheet("QStatusBar::item { border: 0px solid black }; ");