Change QDialog window text color to black
-
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:
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.
-
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:
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.
@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 ofQInputDialog
(that's why you also had to configure the title and content twice).
Either use the static one OR remove thegetItem
and work with yourinput_dialog
instanceNot 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() )