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 Offline
    J Offline
    john_hobbyist
    wrote on last edited by
    #1

    Hello, how can I make a pop-up that on the left will have different colors in rectangles and on the right words/data?? I attach a file for help...test.jpg

    JonBJ 1 Reply Last reply
    0
    • J john_hobbyist

      Hello, how can I make a pop-up that on the left will have different colors in rectangles and on the right words/data?? I attach a file for help...test.jpg

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

      @john_hobbyist
      Nothing special for it being a "pop-up". Just a widget with layouts QHBoxLayout & QVBoxLayout, or a QGridLayout if you prefer.

      1 Reply Last reply
      2
      • J Offline
        J Offline
        john_hobbyist
        wrote on last edited by
        #3

        How do I color the boxes?

        eyllanescE 1 Reply Last reply
        0
        • J john_hobbyist

          How do I color the boxes?

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

          @john_hobbyist See https://stackoverflow.com/questions/12655538/how-to-set-qwidget-background-color

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

          J 1 Reply Last reply
          1
          • eyllanescE eyllanesc

            @john_hobbyist See https://stackoverflow.com/questions/12655538/how-to-set-qwidget-background-color

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

            @eyllanesc Thanks! Yes, but it fills the background. I need to color the box inside...

            eyllanescE 1 Reply Last reply
            0
            • J john_hobbyist

              @eyllanesc Thanks! Yes, but it fills the background. I need to color the box inside...

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

              @john_hobbyist I am assuming that the box is a QWidget. If you want more help then show your progress.

              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
              1
              • J Offline
                J Offline
                john_hobbyist
                wrote on last edited by
                #7

                I found this: https://www.geeksforgeeks.org/pyqt5-how-to-change-background-color-of-main-window/ How can I transform it for filling the box color?

                eyllanescE 1 Reply Last reply
                0
                • J john_hobbyist

                  I found this: https://www.geeksforgeeks.org/pyqt5-how-to-change-background-color-of-main-window/ How can I transform it for filling the box color?

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

                  @john_hobbyist QLabel is a QWidget then use self.label.setStyleSheet("border: 1px solid black; background-color: red")

                  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
                  1
                  • J Offline
                    J Offline
                    john_hobbyist
                    wrote on last edited by john_hobbyist
                    #9

                    This is my try, by modifying the above code and this example: https://www.tutorialspoint.com/pyqt/pyqt_qgridlayout_class.htm ! Where do I put this line of code:

                    self.label.setStyleSheet("border: 1px solid black; background-color: red")
                    

                    in order to color the boxes? I tried also with self. etc nothing!

                    import sys
                    from PyQt5.QtCore import *
                    from PyQt5.QtWidgets import *
                    def window():
                        app = QApplication(sys.argv)
                        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()
                        
                        sys.exit(app.exec_())
                         
                    if __name__ == '__main__':
                     window()
                    
                    eyllanescE 1 Reply Last reply
                    0
                    • J john_hobbyist

                      This is my try, by modifying the above code and this example: https://www.tutorialspoint.com/pyqt/pyqt_qgridlayout_class.htm ! Where do I put this line of code:

                      self.label.setStyleSheet("border: 1px solid black; background-color: red")
                      

                      in order to color the boxes? I tried also with self. etc nothing!

                      import sys
                      from PyQt5.QtCore import *
                      from PyQt5.QtWidgets import *
                      def window():
                          app = QApplication(sys.argv)
                          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()
                          
                          sys.exit(app.exec_())
                           
                      if __name__ == '__main__':
                       window()
                      
                      eyllanescE Offline
                      eyllanescE Offline
                      eyllanesc
                      wrote on last edited by
                      #10

                      @john_hobbyist Change:

                      grid.addWidget(QLabel("Yellow"), 1,1)
                      

                      to

                      label_yellow = QLabel("Yellow")
                      label_yellow.setStyleSheet(...)
                      grid.addWidget(label_yellow, 1,1)
                      

                      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
                      1
                      • J Offline
                        J Offline
                        john_hobbyist
                        wrote on last edited by
                        #11

                        I made the above code a method and I call it from PyQt5 GUI. The result is this:

                        QWidget::setLayout: Attempting to set QLayout "" on TestCode"", which already has a layout
                        QCoreApplication::exec: The event loop is already running
                        Segmentation fault (core dumped)
                        

                        Any ideas what is wrong?

                        The method is this:

                        def PrintGridLayout (self):
                         ....
                        
                        jsulmJ 1 Reply Last reply
                        0
                        • J john_hobbyist

                          I made the above code a method and I call it from PyQt5 GUI. The result is this:

                          QWidget::setLayout: Attempting to set QLayout "" on TestCode"", which already has a layout
                          QCoreApplication::exec: The event loop is already running
                          Segmentation fault (core dumped)
                          

                          Any ideas what is wrong?

                          The method is this:

                          def PrintGridLayout (self):
                           ....
                          
                          jsulmJ Online
                          jsulmJ Online
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

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

                          def PrintGridLayout (self):
                          ....

                          Why don't you post whole code instead of ...?

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

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

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

                            def PrintGridLayout (self):

                            def PrintGridLayout (self):
                                def PrintGridLayout (self):
                                app = QApplication(sys.argv)
                                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()
                                
                                sys.exit(app.exec_())
                            
                            jsulmJ 1 Reply Last reply
                            0
                            • J john_hobbyist

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

                              def PrintGridLayout (self):

                              def PrintGridLayout (self):
                                  def PrintGridLayout (self):
                                  app = QApplication(sys.argv)
                                  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()
                                  
                                  sys.exit(app.exec_())
                              
                              jsulmJ Online
                              jsulmJ Online
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

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

                              def PrintGridLayout (self):
                              def PrintGridLayout (self):

                              Why do you have nested PrintGridLayout?
                              Why do you have "app = QApplication(sys.argv)" and "sys.exit(app.exec_())"? As one of the error messages tells you you already have event loop running!

                              Regarding first error: please read https://doc.qt.io/qt-5/qwidget.html#setLayout

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

                              J 1 Reply Last reply
                              2
                              • jsulmJ jsulm

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

                                def PrintGridLayout (self):
                                def PrintGridLayout (self):

                                Why do you have nested PrintGridLayout?
                                Why do you have "app = QApplication(sys.argv)" and "sys.exit(app.exec_())"? As one of the error messages tells you you already have event loop running!

                                Regarding first error: please read https://doc.qt.io/qt-5/qwidget.html#setLayout

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

                                @jsulm Yes the first one is a copy paste error from Kubuntu to here...

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

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

                                  app = QApplication(sys.argv)" and "sys.exit(app.exec_())

                                  Thanks....I deleted these:

                                  app = QApplication(sys.argv)
                                  

                                  and

                                  sys.exit(app.exec_())
                                  

                                  and now I get only this error:

                                  QWidget::setLayout: Attempting to set QLayout "" on TestCode"", which already has a layout
                                  

                                  which I try to figure out how to solve it... because it shows only this error and nothing else is depicted in the PyQt5 GUI...

                                  By the way, the above method I call it like this:

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

                                  Update 1: However, the rest QAction choices (buttons) work well..

                                  Update 2: I put everywhere inside the method code print commands... everything runs inside the method however nothing is displayed in the GUI...

                                  jsulmJ 1 Reply Last reply
                                  0
                                  • J john_hobbyist

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

                                    app = QApplication(sys.argv)" and "sys.exit(app.exec_())

                                    Thanks....I deleted these:

                                    app = QApplication(sys.argv)
                                    

                                    and

                                    sys.exit(app.exec_())
                                    

                                    and now I get only this error:

                                    QWidget::setLayout: Attempting to set QLayout "" on TestCode"", which already has a layout
                                    

                                    which I try to figure out how to solve it... because it shows only this error and nothing else is depicted in the PyQt5 GUI...

                                    By the way, the above method I call it like this:

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

                                    Update 1: However, the rest QAction choices (buttons) work well..

                                    Update 2: I put everywhere inside the method code print commands... everything runs inside the method however nothing is displayed in the GUI...

                                    jsulmJ Online
                                    jsulmJ Online
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

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

                                    which I try to figure out how to solve it

                                    That's why I suggested to read https://doc.qt.io/qt-5/qwidget.html#setLayout
                                    Especially this part:
                                    "If there already is a layout manager installed on this widget, QWidget won't let you install another. You must first delete the existing layout manager (returned by layout()) before you can call setLayout() with the new layout."

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

                                    1 Reply Last reply
                                    2
                                    • J Offline
                                      J Offline
                                      john_hobbyist
                                      wrote on last edited by john_hobbyist
                                      #18

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

                                      If there already is a layout manager installed on this widget

                                      When to code runs, it opens a main window/GUI, and when the user chooses from the menu (QAction) , he can open an auxiliary window with some information. What should I delete? Both of them are required...

                                      Can you give me an example code, in order to understand?

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

                                        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):
                                              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 1 Reply Last reply
                                        0
                                        • J john_hobbyist

                                          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):
                                                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 Offline
                                          JonBJ Offline
                                          JonB
                                          wrote on last edited by JonB
                                          #20

                                          @john_hobbyist

                                          win = QWidget()
                                          ...
                                          win.setLayout(grid)
                                          

                                          I would not expect this code to generate

                                          QWidget::setLayout: Attempting to set QLayout "" on TestCode"", which already has a layout
                                          

                                          since a blank QWidget does not already have a layout. OTOH, I would expect mainWindow.setLayout() to do so, because QMainWindow does start with a layout. So where exactly are you getting the error from? (I believe Python reports the source code line number in its full message?)

                                          When you copy & paste your code here, could you please take the time to do so correctly, as incorrect code pasting wastes peoples' time trying to understand. I very much doubt your code actually has

                                             def PrintGridLayout (self):
                                                def PrintGridLayout (self):
                                          

                                          as you show.

                                          J 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