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. Pop-up with colors and data
Forum Updated to NodeBB v4.3 + New Features

Pop-up with colors and data

Scheduled Pinned Locked Moved Solved Qt for Python
35 Posts 4 Posters 5.5k 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.
  • J john_hobbyist

    @JonB Ι re-post:

    As I checked from here: https://doc.qt.io/qt-5/layout.html under paragraph: "Qt's Layout Classes":

    I use these classes:

    QHBoxLayout
    

    and

    QSizePolicy
    

    under this method (and after that is the method I described previously):

    class Thing(QMainWindow):
       def __init__(self, parent = None):
          . . . 
          (here are the QHBoxLayout and QSizePolicy used)
    	  . . . 
    
       def PrintGridLayout (self):
          win = QWidget()
          grid=QGridLayout()
        
          grid.addWidget(QLabel("Yellow"), 1,1)
          grid.addWidget(QPushButton("B"+str(1)+str(2)),1,2)
          grid.addWidget(QLabel("Red"), 2,1)
          grid.addWidget(QPushButton("B"+str(2)+str(2)),2,2)
          grid.addWidget(QLabel("Blue"), 3,1)
          grid.addWidget(QPushButton("B"+str(3)+str(2)),3,2)
        
          win.setLayout(grid)
          win.setGeometry(100,100,200,100)
          win.setWindowTitle("PyQt")
          win.show()
    

    So how do I delete the existing layout manager? And especially since they are on a different class??

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by
    #24

    @john_hobbyist
    If you do not get an error message you have nothing to do. If you do get an error message then show it, and find the line which caused in it which I think Python will show in the message. This is the third time I have said this.

    J 1 Reply Last reply
    0
    • JonBJ JonB

      @john_hobbyist
      If you do not get an error message you have nothing to do. If you do get an error message then show it, and find the line which caused in it which I think Python will show in the message. This is the third time I have said this.

      J Offline
      J Offline
      john_hobbyist
      wrote on last edited by
      #25

      @JonB No error, the method above runs (I checked it with print commands among the code). However, no GUI is displayed with the GridLayout, Buttons e.t.c.

      JonBJ 1 Reply Last reply
      0
      • J john_hobbyist

        @JonB No error, the method above runs (I checked it with print commands among the code). However, no GUI is displayed with the GridLayout, Buttons e.t.c.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #26

        @john_hobbyist said in Pop-up with colors and data:

        However, no GUI is displayed with the GridLayout, Buttons e.t.c.

        Could you please tell me: does this mean that an "empty" widget/window is displayed (presumably with title bar PyQt) or does this mean no widget/window at all is shown?

        J 1 Reply Last reply
        0
        • JonBJ JonB

          @john_hobbyist said in Pop-up with colors and data:

          However, no GUI is displayed with the GridLayout, Buttons e.t.c.

          Could you please tell me: does this mean that an "empty" widget/window is displayed (presumably with title bar PyQt) or does this mean no widget/window at all is shown?

          J Offline
          J Offline
          john_hobbyist
          wrote on last edited by
          #27

          @JonB no widget/window at all is shown for this specific method...

          JonBJ 1 Reply Last reply
          0
          • J john_hobbyist

            @JonB no widget/window at all is shown for this specific method...

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #28

            @john_hobbyist
            So two possibilities occur to me:

            • You create a widget (win = QWidget()) but never "attach" it anywhere to your main window. Where do you add it to that?

            • Your win = QWidget() is a local reference which goes out of scope at the end of PrintGridLayout in Python, doesn't it? So won't it get destroyed, and hence no widget is shown?

            So far as I can tell from what you are saying, you might as well remove all your QGridLayout code and you would see the same thing. So it has nothing to do with using the layout, it just isn't showing the widget?

            J 1 Reply Last reply
            0
            • JonBJ JonB

              @john_hobbyist
              So two possibilities occur to me:

              • You create a widget (win = QWidget()) but never "attach" it anywhere to your main window. Where do you add it to that?

              • Your win = QWidget() is a local reference which goes out of scope at the end of PrintGridLayout in Python, doesn't it? So won't it get destroyed, and hence no widget is shown?

              So far as I can tell from what you are saying, you might as well remove all your QGridLayout code and you would see the same thing. So it has nothing to do with using the layout, it just isn't showing the widget?

              J Offline
              J Offline
              john_hobbyist
              wrote on last edited by john_hobbyist
              #29

              @JonB said in Pop-up with colors and data:

              @john_hobbyist
              So two possibilities occur to me:

              1. You create a widget (win = QWidget()) but never "attach" it anywhere to your main window. Where do you add it to that?

              2. Your win = QWidget() is a local reference which goes out of scope at the end of PrintGridLayout in Python, doesn't it? So won't it get destroyed, and hence no widget is shown?

              3. So far as I can tell from what you are saying, you might as well remove all your QGridLayout code and you would see the same thing. So it has nothing to do with using the layout, it just isn't showing the widget?

              1. Nowhere

              2. I am not sure...I think yes

              3. Yes, either I have the method or I do not have it, it is the same thing...nothing displayed...

              JonBJ 1 Reply Last reply
              0
              • J john_hobbyist

                @JonB said in Pop-up with colors and data:

                @john_hobbyist
                So two possibilities occur to me:

                1. You create a widget (win = QWidget()) but never "attach" it anywhere to your main window. Where do you add it to that?

                2. Your win = QWidget() is a local reference which goes out of scope at the end of PrintGridLayout in Python, doesn't it? So won't it get destroyed, and hence no widget is shown?

                3. So far as I can tell from what you are saying, you might as well remove all your QGridLayout code and you would see the same thing. So it has nothing to do with using the layout, it just isn't showing the widget?

                1. Nowhere

                2. I am not sure...I think yes

                3. Yes, either I have the method or I do not have it, it is the same thing...nothing displayed...

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by
                #30

                @john_hobbyist said in Pop-up with colors and data:

                Yes, either I have the method or I do not have it, it is the same thing...nothing displayed...

                So you should start by mentioning that! :)

                Can we take a step back. What are you trying to do? You have a QMainWindow. That comes with its own layout, all described in Qt Main Window Framework. Are you just wanting to set its central widget to this grid?

                If per your title it's supposed to be a "popup" window, you'd have to look up "popup", or use a modeless dialog, I'm not sure about that bit.

                For now, try changing your

                win = QWidget()
                

                to

                self.win = QWidget(self)
                

                and obviously those mentions of win... to self.win.... Better?

                J 1 Reply Last reply
                0
                • JonBJ JonB

                  @john_hobbyist said in Pop-up with colors and data:

                  Yes, either I have the method or I do not have it, it is the same thing...nothing displayed...

                  So you should start by mentioning that! :)

                  Can we take a step back. What are you trying to do? You have a QMainWindow. That comes with its own layout, all described in Qt Main Window Framework. Are you just wanting to set its central widget to this grid?

                  If per your title it's supposed to be a "popup" window, you'd have to look up "popup", or use a modeless dialog, I'm not sure about that bit.

                  For now, try changing your

                  win = QWidget()
                  

                  to

                  self.win = QWidget(self)
                  

                  and obviously those mentions of win... to self.win.... Better?

                  J Offline
                  J Offline
                  john_hobbyist
                  wrote on last edited by
                  #31

                  @JonB said in Pop-up with colors and data:

                  @john_hobbyist said in Pop-up with colors and data:

                  Yes, either I have the method or I do not have it, it is the same thing...nothing displayed...

                  So you should start by mentioning that! :)

                  Can we take a step back. What are you trying to do? You have a QMainWindow. That comes with its own layout, all described in Qt Main Window Framework. Are you just wanting to set its central widget to this grid?

                  If per your title it's supposed to be a "popup" window, you'd have to look up "popup", or use a modeless dialog, I'm not sure about that bit.

                  For now, try changing your

                  win = QWidget()
                  

                  to

                  self.win = QWidget(self)
                  

                  and obviously those mentions of win... to self.win.... Better?

                  I have a QMainWindow that opens, everything ok. It has menus where you choose what you want to see. In one of these menus I have a choice, where, when you choose it a new window should pop-up and show colored boxes and buttons...

                  Yes, I tried it with self.win = QWidget(self) nothing changed, again nothing was displayed....

                  JonBJ 1 Reply Last reply
                  0
                  • J john_hobbyist

                    @JonB said in Pop-up with colors and data:

                    @john_hobbyist said in Pop-up with colors and data:

                    Yes, either I have the method or I do not have it, it is the same thing...nothing displayed...

                    So you should start by mentioning that! :)

                    Can we take a step back. What are you trying to do? You have a QMainWindow. That comes with its own layout, all described in Qt Main Window Framework. Are you just wanting to set its central widget to this grid?

                    If per your title it's supposed to be a "popup" window, you'd have to look up "popup", or use a modeless dialog, I'm not sure about that bit.

                    For now, try changing your

                    win = QWidget()
                    

                    to

                    self.win = QWidget(self)
                    

                    and obviously those mentions of win... to self.win.... Better?

                    I have a QMainWindow that opens, everything ok. It has menus where you choose what you want to see. In one of these menus I have a choice, where, when you choose it a new window should pop-up and show colored boxes and buttons...

                    Yes, I tried it with self.win = QWidget(self) nothing changed, again nothing was displayed....

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #32

                    @john_hobbyist
                    Then I give up. You do call PrintGridLayout(), don't you, and you have checked it is being executed...?

                    J 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @john_hobbyist
                      Then I give up. You do call PrintGridLayout(), don't you, and you have checked it is being executed...?

                      J Offline
                      J Offline
                      john_hobbyist
                      wrote on last edited by john_hobbyist
                      #33

                      @JonB said in Pop-up with colors and data:

                      @john_hobbyist
                      Then I give up. You do call PrintGridLayout(), don't you, and you have checked it is being executed...?

                      Yes I call it from main program like that:

                      test = QAction("Testing Layout", self) 
                      file.addAction(test) # here
                      test.triggered.connect(self.PrintGridLayout)
                      

                      Yes the code runs, but the window is not displayed....

                      Thanks for your try and your time though... :-)

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        john_hobbyist
                        wrote on last edited by john_hobbyist
                        #34

                        It needed:

                        self.setLayout(grid)
                        

                        Thanks for you time! I mark it as solved!

                        JonBJ 1 Reply Last reply
                        0
                        • J john_hobbyist

                          It needed:

                          self.setLayout(grid)
                          

                          Thanks for you time! I mark it as solved!

                          JonBJ Online
                          JonBJ Online
                          JonB
                          wrote on last edited by
                          #35

                          @john_hobbyist
                          If you decided you wanted self.setLayout(grid) --- inside PrintGridLayout () so self is Thing(QMainWindow) right? --- could you explain to me what you wanted the whole win = QWidget() for??

                          Not to mention that if self is a QMainWindow and you go self.setLayout() you should be back to getting the "which already has a layout" warning?

                          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