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. How to populate a dataframe in a QDialog using PyQT
Forum Updated to NodeBB v4.3 + New Features

How to populate a dataframe in a QDialog using PyQT

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 5 Posters 9.2k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    Piyush
    wrote on 5 Feb 2018, 05:41 last edited by
    #1

    Hi,
    I need to display a table in QDialog. How can I do it in Python. Here is the code I am using:
    def onClick(self):
    d = QDialog()
    b1 = QPushButton("ok",d)
    b1.move(50,50)
    d.setWindowTitle("Dialog")
    d.setWindowModality(Qt.ApplicationModal)
    d.setWindowFlags()
    d.exec_()

    T J 2 Replies Last reply 5 Feb 2018, 07:26
    0
    • P Piyush
      5 Feb 2018, 05:41

      Hi,
      I need to display a table in QDialog. How can I do it in Python. Here is the code I am using:
      def onClick(self):
      d = QDialog()
      b1 = QPushButton("ok",d)
      b1.move(50,50)
      d.setWindowTitle("Dialog")
      d.setWindowModality(Qt.ApplicationModal)
      d.setWindowFlags()
      d.exec_()

      T Offline
      T Offline
      Taz742
      wrote on 5 Feb 2018, 07:26 last edited by
      #2

      @Piyush
      Hi. Sorry i dont know what is dataframe, can you explain me?

      Do what you want.

      P 1 Reply Last reply 5 Feb 2018, 08:25
      1
      • P Piyush
        5 Feb 2018, 05:41

        Hi,
        I need to display a table in QDialog. How can I do it in Python. Here is the code I am using:
        def onClick(self):
        d = QDialog()
        b1 = QPushButton("ok",d)
        b1.move(50,50)
        d.setWindowTitle("Dialog")
        d.setWindowModality(Qt.ApplicationModal)
        d.setWindowFlags()
        d.exec_()

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 5 Feb 2018, 08:15 last edited by
        #3

        @Piyush You asked same question here: https://forum.qt.io/topic/87363/pop-up-window-displaying-a-dataframe and got answers. Did you try to do what already was suggested?

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

        P 1 Reply Last reply 5 Feb 2018, 08:30
        2
        • T Taz742
          5 Feb 2018, 07:26

          @Piyush
          Hi. Sorry i dont know what is dataframe, can you explain me?

          P Offline
          P Offline
          Piyush
          wrote on 5 Feb 2018, 08:25 last edited by
          #4

          @Taz742 Its a table. So I am trying to display a table using QDialog but I could not find any way to do that.

          1 Reply Last reply
          0
          • J jsulm
            5 Feb 2018, 08:15

            @Piyush You asked same question here: https://forum.qt.io/topic/87363/pop-up-window-displaying-a-dataframe and got answers. Did you try to do what already was suggested?

            P Offline
            P Offline
            Piyush
            wrote on 5 Feb 2018, 08:30 last edited by
            #5

            @jsulm Hi,
            Actually the answer you gave was not relevant.

            M J 2 Replies Last reply 5 Feb 2018, 08:45
            0
            • P Piyush
              5 Feb 2018, 08:30

              @jsulm Hi,
              Actually the answer you gave was not relevant.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 5 Feb 2018, 08:45 last edited by mrjj 2 May 2018, 08:47
              #6

              @Piyush

              Hi
              To put a table on/in a Dialog.
              You must have your own dialog. So subclass is highly relevant :)
              There is no other way. Except table it self can be window. but then its not dialog like.

              listview example
              https://www.pythoncentral.io/pyside-pyqt-tutorial-qlistview-and-qstandarditemmodel/

              dialog example
              https://gist.github.com/justinfx/1951709

              P 1 Reply Last reply 5 Feb 2018, 08:48
              2
              • P Piyush
                5 Feb 2018, 08:30

                @jsulm Hi,
                Actually the answer you gave was not relevant.

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 5 Feb 2018, 08:47 last edited by
                #7

                @Piyush Please explain why it is not relevant?
                You're trying to use QDialog to show a table. The standard QDialog does not know anything about your table. That's why you need to subclass QDialog and show the table there.

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

                1 Reply Last reply
                2
                • M mrjj
                  5 Feb 2018, 08:45

                  @Piyush

                  Hi
                  To put a table on/in a Dialog.
                  You must have your own dialog. So subclass is highly relevant :)
                  There is no other way. Except table it self can be window. but then its not dialog like.

                  listview example
                  https://www.pythoncentral.io/pyside-pyqt-tutorial-qlistview-and-qstandarditemmodel/

                  dialog example
                  https://gist.github.com/justinfx/1951709

                  P Offline
                  P Offline
                  Piyush
                  wrote on 5 Feb 2018, 08:48 last edited by
                  #8

                  @mrjj Hi,
                  So this is what I am trying to do. But getting an error. "My app object has no attribute set item"

                  self.ui.btn1.clicked.connect(self.Dialog)
                  def Dialog(self):
                  table = self.MyTable(data,5,3)
                  #table.setWindowFlags(table.windowFlags() | Qt.Window)
                  table.show()
                  self.table = table

                  def MyTable(self,data,*args):
                       QTableWidget.__init__(self)
                       self.data = data
                       horHeaders = []
                       for n, key in enumerate(sorted(self.data.keys())):
                          horHeaders.append(key)
                          for m, item in enumerate(self.data[key]):
                              newitem = QTableWidgetItem(item)
                              self.setItem(m, n, newitem)
                              self.setHorizontalHeaderLabels(horHeaders)
                       print horHeaders,newitem
                  
                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 5 Feb 2018, 08:50 last edited by
                    #9

                    Hi
                    you must call setItem(m, n, newitem) on the QTableWidget not via Self since in this case Self seems to be app.

                    P 1 Reply Last reply 5 Feb 2018, 08:55
                    1
                    • M mrjj
                      5 Feb 2018, 08:50

                      Hi
                      you must call setItem(m, n, newitem) on the QTableWidget not via Self since in this case Self seems to be app.

                      P Offline
                      P Offline
                      Piyush
                      wrote on 5 Feb 2018, 08:55 last edited by
                      #10

                      @mrjj Hi,
                      I tried that too but getting an error: "TypeError: setItem(self, int, int, QTableWidgetItem): first argument of unbound method must have type 'QTableWidget'"

                      J 1 Reply Last reply 5 Feb 2018, 09:09
                      0
                      • P Piyush
                        5 Feb 2018, 08:55

                        @mrjj Hi,
                        I tried that too but getting an error: "TypeError: setItem(self, int, int, QTableWidgetItem): first argument of unbound method must have type 'QTableWidget'"

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 5 Feb 2018, 09:09 last edited by
                        #11

                        @Piyush

                        QTableWidget.setItem(m, n, newitem)
                        

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

                        P 1 Reply Last reply 5 Feb 2018, 09:16
                        0
                        • J jsulm
                          5 Feb 2018, 09:09

                          @Piyush

                          QTableWidget.setItem(m, n, newitem)
                          
                          P Offline
                          P Offline
                          Piyush
                          wrote on 5 Feb 2018, 09:16 last edited by
                          #12

                          @jsulm Hi,
                          I have used the same line of code. But still I am getting the error: "TypeError: setItem(self, int, int, QTableWidgetItem): first argument of unbound method must have type 'QTableWidget'". Here is the snippet:

                          def Dialog(self):
                               table = self.MyTable(data,5,3)
                               table.show()
                               self.table = table
                               
                          def MyTable(self,data,*args):
                               self.data = data
                               horHeaders = []
                               for n, key in enumerate(sorted(self.data.keys())):
                                  horHeaders.append(key)
                                  for m, item in enumerate(self.data[key]):
                                      newitem = QTableWidgetItem(item)
                                      QTableWidget.setItem(m, n, newitem)
                                      QTableWidget.setHorizontalHeaderLabels(horHeaders)
                               print horHeaders,newitem
                          
                          J JonBJ 2 Replies Last reply 5 Feb 2018, 09:26
                          0
                          • P Piyush
                            5 Feb 2018, 09:16

                            @jsulm Hi,
                            I have used the same line of code. But still I am getting the error: "TypeError: setItem(self, int, int, QTableWidgetItem): first argument of unbound method must have type 'QTableWidget'". Here is the snippet:

                            def Dialog(self):
                                 table = self.MyTable(data,5,3)
                                 table.show()
                                 self.table = table
                                 
                            def MyTable(self,data,*args):
                                 self.data = data
                                 horHeaders = []
                                 for n, key in enumerate(sorted(self.data.keys())):
                                    horHeaders.append(key)
                                    for m, item in enumerate(self.data[key]):
                                        newitem = QTableWidgetItem(item)
                                        QTableWidget.setItem(m, n, newitem)
                                        QTableWidget.setHorizontalHeaderLabels(horHeaders)
                                 print horHeaders,newitem
                            
                            J Offline
                            J Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on 5 Feb 2018, 09:26 last edited by
                            #13

                            @Piyush Maybe

                            super(QTableWidget, self).setItem(m, n, newitem)
                            

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

                            P 1 Reply Last reply 5 Feb 2018, 09:35
                            0
                            • P Piyush
                              5 Feb 2018, 09:16

                              @jsulm Hi,
                              I have used the same line of code. But still I am getting the error: "TypeError: setItem(self, int, int, QTableWidgetItem): first argument of unbound method must have type 'QTableWidget'". Here is the snippet:

                              def Dialog(self):
                                   table = self.MyTable(data,5,3)
                                   table.show()
                                   self.table = table
                                   
                              def MyTable(self,data,*args):
                                   self.data = data
                                   horHeaders = []
                                   for n, key in enumerate(sorted(self.data.keys())):
                                      horHeaders.append(key)
                                      for m, item in enumerate(self.data[key]):
                                          newitem = QTableWidgetItem(item)
                                          QTableWidget.setItem(m, n, newitem)
                                          QTableWidget.setHorizontalHeaderLabels(horHeaders)
                                   print horHeaders,newitem
                              
                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on 5 Feb 2018, 09:33 last edited by JonB 2 May 2018, 09:38
                              #14

                              @Piyush said in How to populate a dataframe in a QDialog using PyQT:

                                      QTableWidget.setItem(m, n, newitem)
                                      QTableWidget.setHorizontalHeaderLabels(horHeaders)
                              

                              The left hand side for setItem()/setHorizontalHeaderLabels() must be your actual table (widget) variable. You are passing the class/type QTableWidget. Hence the error message.

                              Also while I'm here, your MyTable() does not return anything, and does not inherit from anything either.

                              P J 2 Replies Last reply 5 Feb 2018, 09:43
                              0
                              • J jsulm
                                5 Feb 2018, 09:26

                                @Piyush Maybe

                                super(QTableWidget, self).setItem(m, n, newitem)
                                
                                P Offline
                                P Offline
                                Piyush
                                wrote on 5 Feb 2018, 09:35 last edited by
                                #15

                                @jsulm said in How to populate a dataframe in a QDialog using PyQT:

                                super(QTableWidget, self).setItem(m, n, newitem)

                                Actually no, since super will call a class object.

                                1 Reply Last reply
                                0
                                • JonBJ JonB
                                  5 Feb 2018, 09:33

                                  @Piyush said in How to populate a dataframe in a QDialog using PyQT:

                                          QTableWidget.setItem(m, n, newitem)
                                          QTableWidget.setHorizontalHeaderLabels(horHeaders)
                                  

                                  The left hand side for setItem()/setHorizontalHeaderLabels() must be your actual table (widget) variable. You are passing the class/type QTableWidget. Hence the error message.

                                  Also while I'm here, your MyTable() does not return anything, and does not inherit from anything either.

                                  P Offline
                                  P Offline
                                  Piyush
                                  wrote on 5 Feb 2018, 09:43 last edited by
                                  #16

                                  @JonB Hi,
                                  Could you give me the code for that? Since I am not able to get it.

                                  JonBJ J 2 Replies Last reply 5 Feb 2018, 09:45
                                  0
                                  • JonBJ JonB
                                    5 Feb 2018, 09:33

                                    @Piyush said in How to populate a dataframe in a QDialog using PyQT:

                                            QTableWidget.setItem(m, n, newitem)
                                            QTableWidget.setHorizontalHeaderLabels(horHeaders)
                                    

                                    The left hand side for setItem()/setHorizontalHeaderLabels() must be your actual table (widget) variable. You are passing the class/type QTableWidget. Hence the error message.

                                    Also while I'm here, your MyTable() does not return anything, and does not inherit from anything either.

                                    J Offline
                                    J Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 5 Feb 2018, 09:45 last edited by
                                    #17

                                    @JonB Somehow I was thinking MyTable is a class derived from QTableWidget :-)

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

                                    1 Reply Last reply
                                    0
                                    • P Piyush
                                      5 Feb 2018, 09:43

                                      @JonB Hi,
                                      Could you give me the code for that? Since I am not able to get it.

                                      JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on 5 Feb 2018, 09:45 last edited by
                                      #18

                                      @Piyush
                                      Well, (as usual for me) I don't really understand what it is you are trying to do or ask about.

                                      Are you simply wishing to create a QDialog and then put a QTableWidget on it, so it's a dialog which has a table (among possibly other widgets) on it?

                                      P 1 Reply Last reply 5 Feb 2018, 09:49
                                      0
                                      • P Piyush
                                        5 Feb 2018, 09:43

                                        @JonB Hi,
                                        Could you give me the code for that? Since I am not able to get it.

                                        J Offline
                                        J Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on 5 Feb 2018, 09:46 last edited by
                                        #19

                                        @Piyush said in How to populate a dataframe in a QDialog using PyQT:

                                        Could you give me the code for that? Since I am not able to get it.

                                        In your dialog you should have an instance of QTableWidget, right?
                                        Something like:

                                        self.tableWidget = QTableWidget()
                                        

                                        Then it would be

                                        self.tableWidget.setItem(m, n, newitem)
                                        

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

                                        P 1 Reply Last reply 5 Feb 2018, 09:54
                                        0
                                        • JonBJ JonB
                                          5 Feb 2018, 09:45

                                          @Piyush
                                          Well, (as usual for me) I don't really understand what it is you are trying to do or ask about.

                                          Are you simply wishing to create a QDialog and then put a QTableWidget on it, so it's a dialog which has a table (among possibly other widgets) on it?

                                          P Offline
                                          P Offline
                                          Piyush
                                          wrote on 5 Feb 2018, 09:49 last edited by
                                          #20

                                          @JonB Exactly, I want a QDialog and then put a table on it.

                                          J JonBJ 2 Replies Last reply 5 Feb 2018, 09:54
                                          0

                                          4/24

                                          5 Feb 2018, 08:25

                                          20 unread
                                          • Login

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