Unsolved SetStyleSheet does not set back-ground color when QT_Device_Pixel_Ratio environment variable is set to 2
-
Hello,
I'm using Qt 5.5 and working on GUI application with widgets. The Application UI looked very small and cramped in the High Resolution monitors(QHD and 4k). Since Qt 5.5 do not have support for High DPI scaling i have used QT_DEVICE_PIXEL_RATIO environment variable (Experimental Feature in Qt 5.5) to make the application UI better.
In my application, i have a editText Widget and i have to change the background-color of the widget(not background color of the "text" in the widget ) on button click. Using QSS i achieved it. However, when i set the QT_DEVICE_PIXEL_RATIO environment variable to "2" , the background-color remains white irrespective of the color value i provide in the QSS.I hard coded the color value in the QSS to confirm. The color mentioned in QSS is not reflected and background remains white.
Is this a bug in Qt 5.5?
Is there any work around to set a background color to widget?I tried using QPalette, it changes the color from white to the color i choose,but only when the TextEdit is shown for the first time. Next time when i press the color change button the Background color does not change from the current color(if i close the textEdit and reopened it, then the changed color is reflected ).
// Hard coded color values myText->setStyleSheet("color: yellow; background-color: blue !important;"); //Doesnot work when QT_Device_Pixel_Ratio is set to 2
The application runs in Windows 10.
Thank You.Edit:
- Even without !important it did not work, just added it to know whether it helps.
-
Hi
the last part " !important"
is not actually part of the style sheet, correct ?
Just to draw attention to the color.also, you need to stay on 5.5 ? and why?
-
Hiii,
"Just to draw attention to the color."
Yes, Even without '!important' it did not work. I just tried to know whether adding this makes it work.The Entire application is developed in Qt 5.5. I'm just trying to make it look good in High DPI monitors. So can't migrate to advanced version just for this.
Thank You.
-
Hi
ok.
It just seems odd that QT_DEVICE_PIXEL_RATIO should have any
effect on the color.
Might be a bug.
You could try with 5.6 to see if makes any difference. -
@mrjj said in SetStyleSheet does not set back-ground color when QT_Device_Pixel_Ratio environment variable is set to 2:
Hi
ok.
It just seems odd that QT_DEVICE_PIXEL_RATIO should have any
effect on the color.
Might be a bug.
You could try with 5.6 to see if makes any difference.I tried with Qt5.6 and yes it works. Thank You.
But, as of now I can not migrate to 5.6. So I have to go with QPalette and find why it does not get updated.Here is the code
//implementation using palette widget->setAutoFillBackground(true); Palette px = widget->palette(); px.setColor(QPalette::Base,nextColor); //QPalette::Background also does not help widget->setPalette(); widget->setUpdatesEnabled(true); widget->update(); widget->repaint(); qApp->processEvents(); widget->show();