How do I make text invisible using PyQt5?
-
I have a label that I want it not to appear until the user clicks a button, how can I make the text invisible?
-
@_jao_victor_ Why not simply set the text when the button is clicked? So, as default text you set empty string and as soon as the button is clicked you set the actual text.
-
@jsulm I'm already using this technique, but isn't there any probity that makes it invisible?
-
@_jao_victor_ One possible solution is to hide and show the QLabel.
import sys from PySide2.QtWidgets import QApplication, QLabel, QPushButton, QWidget class Widget(QWidget): def __init__(self): super().__init__() self.resize(500, 500) self.button = QPushButton("Foo", self) self.label = QLabel("Bar", self) self.label.move(10, 100) self.label.hide() self.button.clicked.connect(self.handle_clicked) def handle_clicked(self): self.label.setVisible(not self.label.isVisible()) self.label.adjustSize() if __name__ == "__main__": app = QApplication(sys.argv) w = Widget() w.show() sys.exit(app.exec_())
-
@_jao_victor_ said in How do I make text invisible using PyQt5?:
but isn't there any probity that makes it invisible?
You can hide the whole QLabel, but not its text as this feature is redundant because you can simply set empty string.
-
@_jao_victor_
As @jsulm has said. If you really do not want to reset the text to empty, you might instead set its foreground color to whatever the background color of theQLabel
is, that should make the text invisible!