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 11 Aug 2021, 01:58 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?

    J E 2 Replies Last reply 11 Aug 2021, 04:19
    0
    • _ _jao_victor_
      11 Aug 2021, 01:58

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

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 11 Aug 2021, 04:19 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 12 Aug 2021, 00:59 last edited by
        #3

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

        J J 2 Replies Last reply 12 Aug 2021, 04:15
        0
        • _ _jao_victor_
          11 Aug 2021, 01:58

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

          E Offline
          E Offline
          eyllanesc
          wrote on 12 Aug 2021, 01:08 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_
            12 Aug 2021, 00:59

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

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 12 Aug 2021, 04:15 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_
              12 Aug 2021, 00:59

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

              J Offline
              J Offline
              JonB
              wrote on 12 Aug 2021, 06:12 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

              1/6

              11 Aug 2021, 01:58

              • Login

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