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. Change QDialog window text color to black
Forum Updated to NodeBB v4.3 + New Features

Change QDialog window text color to black

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 281 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.
  • R Offline
    R Offline
    Rangerguy128
    wrote on last edited by
    #1

    I've been working on a qdialog window that provides the user the option to choose any of two methods. The problem is that it looks like this:
    246bd9b4-224e-4d7a-9a08-6ba3061af49f-image.png
    This is how I have the code for the window constructed:

    def metodo(self):
            methods = ["Watershed", "Hough Circle"]
            input_dialog = QInputDialog(self)
            input_dialog.setWindowTitle("Choose Method")
            input_dialog.setLabelText("Select counting method:")
            input_dialog.setComboBoxItems(methods)
            # Set a custom stylesheet for QInputDialog
            input_dialog.setStyleSheet("color: black;")
            method, ok = input_dialog.getItem(self, "Choose Method", "Select counting method:", methods, 0, False)
    
            if ok and method:
                if method == "Watershed":
                    self.m = 'w'
                elif method == "Hough Circle":
                    self.m = 'h'
                self.counter()
            else:
                QMessageBox.information(self, "No Selection", "You didn't select a method.")
    

    Any tips? Been trying to change the color of the text to black but it always end up being white.

    Pl45m4P 1 Reply Last reply
    0
    • R Rangerguy128

      I've been working on a qdialog window that provides the user the option to choose any of two methods. The problem is that it looks like this:
      246bd9b4-224e-4d7a-9a08-6ba3061af49f-image.png
      This is how I have the code for the window constructed:

      def metodo(self):
              methods = ["Watershed", "Hough Circle"]
              input_dialog = QInputDialog(self)
              input_dialog.setWindowTitle("Choose Method")
              input_dialog.setLabelText("Select counting method:")
              input_dialog.setComboBoxItems(methods)
              # Set a custom stylesheet for QInputDialog
              input_dialog.setStyleSheet("color: black;")
              method, ok = input_dialog.getItem(self, "Choose Method", "Select counting method:", methods, 0, False)
      
              if ok and method:
                  if method == "Watershed":
                      self.m = 'w'
                  elif method == "Hough Circle":
                      self.m = 'h'
                  self.counter()
              else:
                  QMessageBox.information(self, "No Selection", "You didn't select a method.")
      

      Any tips? Been trying to change the color of the text to black but it always end up being white.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @Rangerguy128 said in Change QDialog window text color to black:

      Any tips? Been trying to change the color of the text to black but it always end up being white.

      Somewhere you must have defined a stylesheet that sets the color to white...
      and you don't see black text, because the dialog you see is this one:

      method, ok = input_dialog.getItem(self, "Choose Method", "Select counting method:", methods, 0, False)
      

      and NOT the one you configured above:

              methods = ["Watershed", "Hough Circle"]
              input_dialog = QInputDialog(self)
              input_dialog.setWindowTitle("Choose Method")
              input_dialog.setLabelText("Select counting method:")
              input_dialog.setComboBoxItems(methods)
              # Set a custom stylesheet for QInputDialog
              input_dialog.setStyleSheet("color: black;")
      

      Try this and you will see:

      def metodo(self):
              methods = ["Watershed", "Hough Circle"]
              input_dialog = QInputDialog(self)
              input_dialog.setWindowTitle("Choose Method")
              input_dialog.setLabelText("Select counting method:")
              input_dialog.setComboBoxItems(methods)
              # Set a custom stylesheet for QInputDialog
              input_dialog.setStyleSheet("color: black;")
              method, ok = input_dialog.getItem(self, "Choose Method", "Select counting method:", methods, 0, False)
              # after you close the white one,
              # the correct dialog with black text should show up
              input_dialog.show() 
      
              if ok and method:
                  if method == "Watershed":
                      self.m = 'w'
                  elif method == "Hough Circle":
                      self.m = 'h'
                  self.counter()
              else:
                  QMessageBox.information(self, "No Selection", "You didn't select a method.")
      

      The reason for this is all the "getXXXXX" method from QInputDialog are static and create their own instance of QInputDialog (that's why you also had to configure the title and content twice).
      Either use the static one OR remove the getItem and work with your input_dialog instance

      Not 100% sure about the syntax, but you can don something like:

      input_dialog.accepted.connect(lambda:
                               if input_dialog.textValue() == "Watershed":
                                  self.m = 'w'
                               elif input_dialog.textValue() == "Hough Circle":
                                   self.m = 'h'
                               self.counter()
                           )
      

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      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