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. SetStyleSheet does not set back-ground color when QT_Device_Pixel_Ratio environment variable is set to 2

SetStyleSheet does not set back-ground color when QT_Device_Pixel_Ratio environment variable is set to 2

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 667 Views
  • 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.
  • P Offline
    P Offline
    Porchezhiyan E
    wrote on last edited by Porchezhiyan E
    #1

    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.
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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?

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Porchezhiyan E
        wrote on last edited by Porchezhiyan E
        #3

        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.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          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.

          P 1 Reply Last reply
          0
          • mrjjM mrjj

            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.

            P Offline
            P Offline
            Porchezhiyan E
            wrote on last edited by Porchezhiyan E
            #5

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