Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set the background color of a OpenGL enhanced QGraphicsView?
Forum Updated to NodeBB v4.3 + New Features

How to set the background color of a OpenGL enhanced QGraphicsView?

Scheduled Pinned Locked Moved General and Desktop
qgraphicsviewopengl
3 Posts 2 Posters 3.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QAndrew
    wrote on last edited by QAndrew
    #1

    I have a custom QGraphicsView class where I try to set the background color in its constructor. These work in non-OpenGL mode:

    QColor backgroundColor(50,50,50,255);
    setBackGroundBrush(backgroundColor);
    

    and

    QPalette myPal = this->palette();
    myPal.setColor(this->backgroundRole(), backgroundColor);
    this->setPalette(myPal);
    

    However in OpenGL mode the first produces a white screen clearing, while the second clears the widget with the given color. I can also see for a few milliseconds the actual item ought to be drawn in between repaints.

    If I don't set the background color at all a white background is set, and everything functions just fine.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      N.Sumi
      wrote on last edited by
      #2

      'Hi...

      If your are working in OPenGL . Then I guess, You can also use

      OpenGLFunctions* f = QOpenGLFunctions;
      f->glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Black

      Q 1 Reply Last reply
      0
      • N N.Sumi

        'Hi...

        If your are working in OPenGL . Then I guess, You can also use

        OpenGLFunctions* f = QOpenGLFunctions;
        f->glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Black

        Q Offline
        Q Offline
        QAndrew
        wrote on last edited by
        #3

        @N.Sumi
        I tried to do this inside my QGraphicsItem::paint() but I get instant crash. I tried with the native brackets and without.

        painter->beginNativePainting();
        QOpenGLFunctions f;
        f.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Black
        painter->endNativePainting();
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved