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. Assign the same font color and the same background color to all QLineEdit components - how does that work?
Qt 6.11 is out! See what's new in the release blog

Assign the same font color and the same background color to all QLineEdit components - how does that work?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 1.4k Views 1 Watching
  • 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
    PythonQTMarlem
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PythonQTMarlem
        wrote on last edited by
        #3

        thank you. but my problem is, how get I a list of all Components of the type QLineEdit.

        JonBJ 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          How are you building your GUI ?
          Which technique are you going to use ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            PythonQTMarlem
            wrote on last edited by PythonQTMarlem
            #5

            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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              There's not a single QLineEdit in your GUI and you did not answer my questions.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • P Offline
                P Offline
                PythonQTMarlem
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • P PythonQTMarlem

                  thank you. but my problem is, how get I a list of all Components of the type QLineEdit.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @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 all QLineEdits in your MainWindow, if that's what you want. However, either of the two solutions suggested by @SGaist would be better than writing code to go through each QLineEdit doing something.

                  1 Reply Last reply
                  1
                  • P Offline
                    P Offline
                    PythonQTMarlem
                    wrote on last edited by PythonQTMarlem
                    #9

                    @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.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @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.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved