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. PyQt, add a widget programmatically, outside the __init__ function
Forum Updated to NodeBB v4.3 + New Features

PyQt, add a widget programmatically, outside the __init__ function

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 407 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.
  • C Offline
    C Offline
    Choz
    wrote on last edited by
    #1

    I am trying to add a QCheckBox programmatically in a form and I am having a problem. If I do it in the init function, it works well and the QCheckBox is showing. But if I add it in a button click event, it does not show. Is there something I am doing wrong?

    def __init__(self, parent=None):
        super(Frm_Test, self).__init__(parent)
        self.setupUi(self)
    
        # THIS WORKS
        test = QCheckBox("Test", self)
        test.move(50, 50)
    
    def btn_importer_click(self):
        # THIS DOESN'T WORK
        test = QCheckBox("Test", self)
        test.move(150, 50)
    
    C 1 Reply Last reply
    0
    • C Choz

      I am trying to add a QCheckBox programmatically in a form and I am having a problem. If I do it in the init function, it works well and the QCheckBox is showing. But if I add it in a button click event, it does not show. Is there something I am doing wrong?

      def __init__(self, parent=None):
          super(Frm_Test, self).__init__(parent)
          self.setupUi(self)
      
          # THIS WORKS
          test = QCheckBox("Test", self)
          test.move(50, 50)
      
      def btn_importer_click(self):
          # THIS DOESN'T WORK
          test = QCheckBox("Test", self)
          test.move(150, 50)
      
      C Offline
      C Offline
      Choz
      wrote on last edited by
      #2

      @Choz I got the answer, I have to call QCheckBox.Show() and it works.

      1 Reply Last reply
      0

      • Login

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