Stylesheet bug(?) on a qplaintextedit



  • I'm working on an application where I've put a qplaintextedit on a popup (Switching between plaintextedit and textedit makes no difference for this issue). Now I'm trying to change the color of the widget and am facing some annoyance:

    These are the two qss lines that impact this widget:

    QWidget { background-color: rgb(57,60,62); }
    QPlainTextEdit {background-color: blue; color: pink;}

    And for a long time, I couldn't get it to change background at all. It does read the qss itself, because the color of the text kept changing. Then I added this line:

    ui->plainTextEdit->setBackgroundVisible(true);

    And got this result:
    texteditbug

    What in the world is going on here? Why is part of the background blue as it's suppose to be but not the part where I actually input the text? Starting a new application I can not reproduce this, but neither can I find any reason as to why this should be happening to begin with. Any tips or ideas would be appreciated. I'm ripping my hair out over here.

    Qt version is 5.9 msvc 2015 32 bit (same issue on 5.7), qtcreator is 4.3.0. Environment is Windows 10.



  • After looking through my application for a few hours, I found a reason altough not a fix for the bug. This only occurs on my custom window dialog. If I use a regular dialogwindow everything works fine.


  • Lifetime Qt Champion

    Hi,

    Can you show the exact code that triggers that ?



  • There's really not a lot of code to show (plus it's all a bit of a spaghetti between several classes). The plaintextedit itself is initiated in QT Designer, which is placed inside a widget which in itself is placed inside custom window. I can't show you any code, but I can show you the workaround I ended up using:

    this->setStyleSheet("background-color: none");
    QPalette p = this->palette();
    p.setColor(QPalette::Base, QColor::fromRgb(57,60,62));
    this->setPalette(p);
    

    The important bit being the "setstylesheet" to have the color "none", as otherwise it would inherit from the stylesheet's qwidget color (which doesn't work in this case).

    If I get the time, I'll try to replicate it in a completely new project which I can share here, so we can try to solve the issue itself instead of hiding the symptoms.


Log in to reply
 

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