Results 1 to 4 of 4

Thread: Background color of GLWidget

  1. #1
    Join Date
    Aug 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Background color of GLWidget

    Is it possible to set the background color of a glWidget? If I use a command such as glClearColor(...) then the whole widget takes that color even though the actual viewport of the openGL might not be covering the whole widget.

  2. #2
    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: Background color of GLWidget

    What do you mean it might not be covering the whole widget?

  3. #3
    Join Date
    Aug 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Background color of GLWidget

    Well with a code like this for example:

    double side = std::min(width / ratio, height);
    glViewport(int(width - side*ratio) / 2, int(height - side) / 2, int(side*ratio), int(side));

    where width and height is the widgets extents, I would get an image thats always a certain ratio 4:3 or 16:9 for example.

  4. #4
    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: Background color of GLWidget

    Ok, but the rest is still occupied by the gl context, so you have to use OpenGL means to change the background color. I think glClear() should clear everything, not only the GL viewport. If I'm mistaken and you are talking about something else, then try using QPalette and changing the background role colour.

Similar Threads

  1. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 00:44
  2. Replies: 1
    Last Post: 5th April 2006, 16:44

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.