Results 1 to 13 of 13

Thread: How to conrol frame of widgets in a QStatuBar?

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How to conrol frame of widgets in a QStatuBar?

    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to conrol frame of widgets in a QStatuBar?

    Yep, the frame seems to be painted by QStatusBar:
    Qt-4.1.2/src/gui/widgets/qstatusbar.cpp (549):
    Qt Code:
    1. style()->drawPrimitive(QStyle::PE_FrameStatusBar, &opt, &p, item->w);
    To copy to clipboard, switch view to plain text mode 

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

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to conrol frame of widgets in a QStatuBar?

    Yes I could...
    But I was hoping its possible already through the existing API that maybe I missed...

    Thanks.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to conrol frame of widgets in a QStatuBar?

    I totally agree this being a bit weird. In my opinion drawing of the status bar widget frames should definitely be optional..
    J-P Nurmi

  5. #5
    Join Date
    May 2007
    Location
    England
    Posts
    56
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to conrol frame of widgets in a QStatuBar?

    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.

  6. #6
    Join Date
    Jun 2007
    Posts
    56
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to conrol frame of widgets in a QStatuBar?

    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 )

    -Mic

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to conrol frame of widgets in a QStatuBar?

    Quote Originally Posted by Micawber View Post
    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.
    J-P Nurmi

  8. #8
    Join Date
    Jun 2007
    Posts
    56
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to conrol frame of widgets in a QStatuBar?

    Yes, I am using QPalette::setPalette()

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

    -Mic

  9. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to conrol frame of widgets in a QStatuBar?

    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..
    J-P Nurmi

  10. #10
    Join Date
    Jun 2007
    Posts
    56
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to conrol frame of widgets in a QStatuBar?

    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!

    Thanks for the suggestion!!!

    -Mic

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to conrol frame of widgets in a QStatuBar?

    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.

  12. #12
    Join Date
    Jun 2007
    Posts
    56
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to conrol frame of widgets in a QStatuBar?

    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.

  13. #13
    Join Date
    May 2008
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to conrol frame of widgets in a QStatuBar?

    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.

    Qt Code:
    1. app.setStyleSheet("QStatusBar::item { border: 0px solid black }; ");
    To copy to clipboard, switch view to plain text mode 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.