Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How do I make text invisible using PyQt5?
Forum Updated to NodeBB v4.3 + New Features

How do I make text invisible using PyQt5?

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 4 Posters 2.1k Views
  • 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.
  • _ Offline
    _ Offline
    _jao_victor_
    wrote on last edited by
    #1

    I have a label that I want it not to appear until the user clicks a button, how can I make the text invisible?

    jsulmJ eyllanescE 2 Replies Last reply
    0
    • _ _jao_victor_

      I have a label that I want it not to appear until the user clicks a button, how can I make the text invisible?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • _ Offline
        _ Offline
        _jao_victor_
        wrote on last edited by
        #3

        @jsulm I'm already using this technique, but isn't there any probity that makes it invisible?

        jsulmJ JonBJ 2 Replies Last reply
        0
        • _ _jao_victor_

          I have a label that I want it not to appear until the user clicks a button, how can I make the text invisible?

          eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by
          #4

          @_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_())
          

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          1 Reply Last reply
          2
          • _ _jao_victor_

            @jsulm I'm already using this technique, but isn't there any probity that makes it invisible?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

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

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • _ _jao_victor_

              @jsulm I'm already using this technique, but isn't there any probity that makes it invisible?

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

              @_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 the QLabel is, that should make the text invisible!

              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