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



  • 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.



  • '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



  • @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();
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.