Unsolved Assign the same font color and the same background color to all QLineEdit components - how does that work?
-
Hello,
My window is derived from QMainWindow. There are a few in this window
Components of the type QLineEdit.Question
How can I give all components for type QLineEdit the same background color
and assign the same font color? -
Hi,
One way is to use a stylesheet.
The other is to create a derived class that provides the visual you want and use that one in place of the original QLineEdit. -
thank you. but my problem is, how get I a list of all Components of the type QLineEdit.
-
How are you building your GUI ?
Which technique are you going to use ? -
so:
class MainWindow(QMainWindow): def __init__(self): # Konstruktor von QMainWindow aufrufen super().__init__() self.setWindowTitle("Marlems barrierefreier PQT-Texteditor") self.setMinimumSize(QSize(900, 370)) self.setWindowIcon(QIcon("PQT-Texteditor.png")) self.showNormal() self.statusBar().showMessage("Willkommen bei Marlems barrierefreier PQT-Texteditor") --- def main(): app = QtWidgets.QApplication([]) win = MainWindow()
Code in PyCharm.
-
There's not a single QLineEdit in your GUI and you did not answer my questions.
-
sorry, then i don't understand what do you want to know.
i have a new class:class QAcccessibilityEdit(QLineEdit): def focusInEvent(self, QFocusEvent): self.setStyleSheet("background-color: " + GlobaleEinstellungen.aktbedienelementhintergrundfarbe)
...
self.editsuchen = QAcccessibilityEdit(self) self.editersetzen = QAcccessibilityEdit(self)
I hope that is the correct answer for your question
-
@PythonQTMarlem said in Assign the same font color and the same background color to all QLineEdit components - how does that work?:
thank you. but my problem is, how get I a list of all Components of the type QLineEdit.
To answer this directly, if I understand you correctly:
win.findChildren(QLineEdit)
will return a list of allQLineEdit
s in yourMainWindow
, if that's what you want. However, either of the two solutions suggested by @SGaist would be better than writing code to go through eachQLineEdit
doing something. -
@JonB said in Assign the same font color and the same background color to all QLineEdit components - how does that work?:
findChildren
thank you, that's what I want.
The two solutions of @SGaist I don't understand or I have no idea how to realize it.
perhaps he can make a codeexample. -
@PythonQTMarlem said in Assign the same font color and the same background color to all QLineEdit components - how does that work?:
class QAcccessibilityEdit(QLineEdit):
def focusInEvent(self, QFocusEvent):
self.setStyleSheet("background-color: " + GlobaleEinstellungen.aktbedienelementhintergrundfarbe)...
self.editsuchen = QAcccessibilityEdit(self)
self.editersetzen = QAcccessibilityEdit(self)You already have a custom class, so now just use it in your code.
One note, do note use name starting with Q, it will only confuse people working on that code thinking it's an official Qt class until they find your custom declaration.