UN-GCPDS / qt-material

Material inspired stylesheet for PySide2, PySide6, PyQt5 and PyQt6
https://qt-material.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
2.3k stars 242 forks source link

QLineEdit - black PlaceholderText #12

Open JackPieCZ opened 3 years ago

JackPieCZ commented 3 years ago

When the script is compiling and the focus is on some other window, the UI window appears with black placeholder text instead of the colour it should be. How it looks like: How it looks when the user didn't click on anything else during compiling:

I tried setStyleSheet("color: my color") but that didn't change anything

YeisonCardona commented 3 years ago

Hi @JackPieCZ

I could not replicate this behavior, I tried with PySide6, PySide2 and PyQt5. The way to set the color for placeholders is modifing the Pallete and not from style sheet, for example:

default_palette = QGuiApplication.palette()
default_palette.setColor(QPalette.PlaceholderText, QColor(255, 0, 0, 128))
QGuiApplication.setPalette(default_palette)

Can you write a small example with the instructions for replicate it?

JackPieCZ commented 3 years ago

Hi @YeisonCardona I'm sorry for not responding lately. Here's an example code of QLineEdit with a placeholder:

#!/usr/bin/python
import sys
from PyQt5.QtWidgets import (QApplication, QLabel, QLineEdit,
                             QVBoxLayout, QWidget)
import qt_material

class Example(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        hbox = QVBoxLayout(self)

        self.lbl = QLabel(self)
        qle = QLineEdit(self)
        qle.setPlaceholderText("Place holder text")

        qle.textChanged[str].connect(self.onChanged)

        hbox.addWidget(qle)
        hbox.addSpacing(20)
        hbox.addWidget(self.lbl)

        self.resize(250, 200)
        self.setWindowTitle('QLineEdit')
        self.show()

    def onChanged(self, text):
        self.lbl.setText(text)
        self.lbl.adjustSize()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    qt_material.apply_stylesheet(app, theme="dark_blue.xml")
    sys.exit(app.exec_())

Here's the video showing the bug (I'm sorry for the low resolution, I had to fit it in 10MB):

https://user-images.githubusercontent.com/72486584/103899689-0bcc1380-50f7-11eb-8579-3ad212709aa3.mp4

YeisonCardona commented 3 years ago

Hi @JackPieCZ

if you change the line with self.show() for self.showMinimized() this behavior happens all time?

JackPieCZ commented 3 years ago

Yes, exactly.

YeisonCardona commented 3 years ago

Ok, so the bug happens when the window (or the widget) does not initialize focused. I will ask for a new test, please add a second "LineEdit", in this way we can know if is about the widget focus.

JackPieCZ commented 3 years ago

I added another LineEdit it behaves the same way as the first one. Here's an example using self.showMinimized(): image

JackPieCZ commented 3 years ago

And, I just witnessed a very weird thing which I'm not very sure how to interpret. I'm using two monitors and when I click at something on the second one (the other one than where the script is running) the colour of placeholders goes back to normal but when I click back at the running window it turns black again. So I think it has to be something with the focus of the widget or the whole window as you suggested.

milahu commented 1 year ago

same here ... https://github.com/rizinorg/cutter/pull/2952#discussion_r1109708326

wrong color with "native" theme, right color with "dark" theme of cutter seems like QPalette.PlaceholderText is missing in the "native" palette (qt breeze dark)

milahu commented 1 year ago

qt6 bug, see also

https://bugreports.qt.io/browse/QTBUG-86195 https://bugreports.qt.io/browse/QTCREATORBUG-25444 https://github.com/Alexhuszagh/BreezeStyleSheets/issues/44