Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get widget background QColor

Tags:

qt

qwidget

I am trying to find out the background color of a QWidget or QGLWidget so that I can use it with qglClearColor() to make the OpenGL part appear natively within the widget (without for example a black background).

I figured I could fetch backgroundRole() of my widget but I am having problems converting it to a QColor. There is QPalette::color(QColorRole) but it isn't static and I have no idea how I would have to create an instance of QPalette to do the transformation.

like image 997
Nils Werner Avatar asked Mar 20 '13 09:03

Nils Werner


People also ask

How do I make my widget background black?

Open your device's Settings app . Select Accessibility. Under "Display," turn on Dark theme.

How do I change the background color of Qframe?

ui->frame->setStyleSheet(""); ui->frame->setStyleSheet("background-color: rgb(255,255,255)");


1 Answers

Use QWidget::palette().color(QWidget::backgroundRole())to receive the color of the background color role for that widget. Obviously, this should also work with any class that inherits QWidget.

like image 146
Sir Digby Chicken Caesar Avatar answered Oct 19 '22 05:10

Sir Digby Chicken Caesar