Adding widgets to qtablewidget pyqt










10














Is there anyway to add like a button in qtablewidget? But the date within the cell would stil have to be displaying, for example if an user double clicked a cell, could i send a signal like a button? Thanks!



edititem():



def editItem(self,clicked):
if clicked.row() == 0:
#go to tab1
if clicked.row() == 1:
#go to tab1
if clicked.row() == 2:
#go to tab1
if clicked.row() == 3:
#go to tab1


table trigger:



self.table1.itemDoubleClicked.connect(self.editItem)









share|improve this question




























    10














    Is there anyway to add like a button in qtablewidget? But the date within the cell would stil have to be displaying, for example if an user double clicked a cell, could i send a signal like a button? Thanks!



    edititem():



    def editItem(self,clicked):
    if clicked.row() == 0:
    #go to tab1
    if clicked.row() == 1:
    #go to tab1
    if clicked.row() == 2:
    #go to tab1
    if clicked.row() == 3:
    #go to tab1


    table trigger:



    self.table1.itemDoubleClicked.connect(self.editItem)









    share|improve this question


























      10












      10








      10


      1





      Is there anyway to add like a button in qtablewidget? But the date within the cell would stil have to be displaying, for example if an user double clicked a cell, could i send a signal like a button? Thanks!



      edititem():



      def editItem(self,clicked):
      if clicked.row() == 0:
      #go to tab1
      if clicked.row() == 1:
      #go to tab1
      if clicked.row() == 2:
      #go to tab1
      if clicked.row() == 3:
      #go to tab1


      table trigger:



      self.table1.itemDoubleClicked.connect(self.editItem)









      share|improve this question















      Is there anyway to add like a button in qtablewidget? But the date within the cell would stil have to be displaying, for example if an user double clicked a cell, could i send a signal like a button? Thanks!



      edititem():



      def editItem(self,clicked):
      if clicked.row() == 0:
      #go to tab1
      if clicked.row() == 1:
      #go to tab1
      if clicked.row() == 2:
      #go to tab1
      if clicked.row() == 3:
      #go to tab1


      table trigger:



      self.table1.itemDoubleClicked.connect(self.editItem)






      python pyqt qtablewidget






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 20 '12 at 14:01

























      asked Aug 17 '12 at 15:56







      user1582983





























          1 Answer
          1






          active

          oldest

          votes


















          16














          You have a couple of questions rolled into one...short answer, yes, you can add a button to a QTableWidget - you can add any widget to the table widget by calling setCellWidget:



          # initialize a table somehow
          table = QTableWidget(parent)
          table.setRowCount(1)
          table.setColumnCount(1)

          # create an cell widget
          btn = QPushButton(table)
          btn.setText('12/1/12')
          table.setCellWidget(0, 0, btn)


          But that doesn't sound like what you actually want.



          It sounds like you want to react to a user double-clicking one of your cells, as though they clicked a button, presumably to bring up a dialog or editor or something.



          If that is the case, all you really need to do is connect to the itemDoubleClicked signal from the QTableWidget, like so:



          def editItem(item):
          print 'editing', item.text()

          # initialize a table widget somehow
          table = QTableWidget(parent)
          table.setRowCount(1)
          table.setColumnCount(1)

          # create an item
          item = QTableWidgetItem('12/1/12')
          table.setItem(0, 0, item)

          # if you don't want to allow in-table editing, either disable the table like:
          table.setEditTriggers( QTableWidget.NoEditTriggers )

          # or specifically for this item
          item.setFlags( item.flags() ^ Qt.ItemIsEditable)

          # create a connection to the double click event
          table.itemDoubleClicked.connect(editItem)





          share|improve this answer




















          • How can I make the row so that when the user clicks the row is highlighted and not the individual cell.
            – user1582983
            Aug 17 '12 at 17:22






          • 3




            do: table.setSelectionBehavior( QTableWidget.SelectRows )
            – Eric Hulser
            Aug 17 '12 at 17:27










          • Also, is there anyway that i can redirect to a different tab when a certain row is clicked? My question is can I basically redirect to a different tab, sort of like a hyperlink on a html webpage.
            – user1582983
            Aug 17 '12 at 17:53










          • Redirect or move to a tab when a button is clicked? Any ideas.
            – user1582983
            Aug 17 '12 at 20:17






          • 2




            You're setting it on the wrong widget - QWidget's don't have that property. I'm assuming if you are trying to set a tab, then somewhere you have a Tab Widget - that's where you have to set the index value. qt-project.org/doc/qt-4.8/qtabwidget.html No offense, but I've answered your question, you're now on a new question - I'd post that if you're still having trouble with more code examples and not keep pushing this one into a new topic.
            – Eric Hulser
            Aug 20 '12 at 18:21










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12009134%2fadding-widgets-to-qtablewidget-pyqt%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown
























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          16














          You have a couple of questions rolled into one...short answer, yes, you can add a button to a QTableWidget - you can add any widget to the table widget by calling setCellWidget:



          # initialize a table somehow
          table = QTableWidget(parent)
          table.setRowCount(1)
          table.setColumnCount(1)

          # create an cell widget
          btn = QPushButton(table)
          btn.setText('12/1/12')
          table.setCellWidget(0, 0, btn)


          But that doesn't sound like what you actually want.



          It sounds like you want to react to a user double-clicking one of your cells, as though they clicked a button, presumably to bring up a dialog or editor or something.



          If that is the case, all you really need to do is connect to the itemDoubleClicked signal from the QTableWidget, like so:



          def editItem(item):
          print 'editing', item.text()

          # initialize a table widget somehow
          table = QTableWidget(parent)
          table.setRowCount(1)
          table.setColumnCount(1)

          # create an item
          item = QTableWidgetItem('12/1/12')
          table.setItem(0, 0, item)

          # if you don't want to allow in-table editing, either disable the table like:
          table.setEditTriggers( QTableWidget.NoEditTriggers )

          # or specifically for this item
          item.setFlags( item.flags() ^ Qt.ItemIsEditable)

          # create a connection to the double click event
          table.itemDoubleClicked.connect(editItem)





          share|improve this answer




















          • How can I make the row so that when the user clicks the row is highlighted and not the individual cell.
            – user1582983
            Aug 17 '12 at 17:22






          • 3




            do: table.setSelectionBehavior( QTableWidget.SelectRows )
            – Eric Hulser
            Aug 17 '12 at 17:27










          • Also, is there anyway that i can redirect to a different tab when a certain row is clicked? My question is can I basically redirect to a different tab, sort of like a hyperlink on a html webpage.
            – user1582983
            Aug 17 '12 at 17:53










          • Redirect or move to a tab when a button is clicked? Any ideas.
            – user1582983
            Aug 17 '12 at 20:17






          • 2




            You're setting it on the wrong widget - QWidget's don't have that property. I'm assuming if you are trying to set a tab, then somewhere you have a Tab Widget - that's where you have to set the index value. qt-project.org/doc/qt-4.8/qtabwidget.html No offense, but I've answered your question, you're now on a new question - I'd post that if you're still having trouble with more code examples and not keep pushing this one into a new topic.
            – Eric Hulser
            Aug 20 '12 at 18:21















          16














          You have a couple of questions rolled into one...short answer, yes, you can add a button to a QTableWidget - you can add any widget to the table widget by calling setCellWidget:



          # initialize a table somehow
          table = QTableWidget(parent)
          table.setRowCount(1)
          table.setColumnCount(1)

          # create an cell widget
          btn = QPushButton(table)
          btn.setText('12/1/12')
          table.setCellWidget(0, 0, btn)


          But that doesn't sound like what you actually want.



          It sounds like you want to react to a user double-clicking one of your cells, as though they clicked a button, presumably to bring up a dialog or editor or something.



          If that is the case, all you really need to do is connect to the itemDoubleClicked signal from the QTableWidget, like so:



          def editItem(item):
          print 'editing', item.text()

          # initialize a table widget somehow
          table = QTableWidget(parent)
          table.setRowCount(1)
          table.setColumnCount(1)

          # create an item
          item = QTableWidgetItem('12/1/12')
          table.setItem(0, 0, item)

          # if you don't want to allow in-table editing, either disable the table like:
          table.setEditTriggers( QTableWidget.NoEditTriggers )

          # or specifically for this item
          item.setFlags( item.flags() ^ Qt.ItemIsEditable)

          # create a connection to the double click event
          table.itemDoubleClicked.connect(editItem)





          share|improve this answer




















          • How can I make the row so that when the user clicks the row is highlighted and not the individual cell.
            – user1582983
            Aug 17 '12 at 17:22






          • 3




            do: table.setSelectionBehavior( QTableWidget.SelectRows )
            – Eric Hulser
            Aug 17 '12 at 17:27










          • Also, is there anyway that i can redirect to a different tab when a certain row is clicked? My question is can I basically redirect to a different tab, sort of like a hyperlink on a html webpage.
            – user1582983
            Aug 17 '12 at 17:53










          • Redirect or move to a tab when a button is clicked? Any ideas.
            – user1582983
            Aug 17 '12 at 20:17






          • 2




            You're setting it on the wrong widget - QWidget's don't have that property. I'm assuming if you are trying to set a tab, then somewhere you have a Tab Widget - that's where you have to set the index value. qt-project.org/doc/qt-4.8/qtabwidget.html No offense, but I've answered your question, you're now on a new question - I'd post that if you're still having trouble with more code examples and not keep pushing this one into a new topic.
            – Eric Hulser
            Aug 20 '12 at 18:21













          16












          16








          16






          You have a couple of questions rolled into one...short answer, yes, you can add a button to a QTableWidget - you can add any widget to the table widget by calling setCellWidget:



          # initialize a table somehow
          table = QTableWidget(parent)
          table.setRowCount(1)
          table.setColumnCount(1)

          # create an cell widget
          btn = QPushButton(table)
          btn.setText('12/1/12')
          table.setCellWidget(0, 0, btn)


          But that doesn't sound like what you actually want.



          It sounds like you want to react to a user double-clicking one of your cells, as though they clicked a button, presumably to bring up a dialog or editor or something.



          If that is the case, all you really need to do is connect to the itemDoubleClicked signal from the QTableWidget, like so:



          def editItem(item):
          print 'editing', item.text()

          # initialize a table widget somehow
          table = QTableWidget(parent)
          table.setRowCount(1)
          table.setColumnCount(1)

          # create an item
          item = QTableWidgetItem('12/1/12')
          table.setItem(0, 0, item)

          # if you don't want to allow in-table editing, either disable the table like:
          table.setEditTriggers( QTableWidget.NoEditTriggers )

          # or specifically for this item
          item.setFlags( item.flags() ^ Qt.ItemIsEditable)

          # create a connection to the double click event
          table.itemDoubleClicked.connect(editItem)





          share|improve this answer












          You have a couple of questions rolled into one...short answer, yes, you can add a button to a QTableWidget - you can add any widget to the table widget by calling setCellWidget:



          # initialize a table somehow
          table = QTableWidget(parent)
          table.setRowCount(1)
          table.setColumnCount(1)

          # create an cell widget
          btn = QPushButton(table)
          btn.setText('12/1/12')
          table.setCellWidget(0, 0, btn)


          But that doesn't sound like what you actually want.



          It sounds like you want to react to a user double-clicking one of your cells, as though they clicked a button, presumably to bring up a dialog or editor or something.



          If that is the case, all you really need to do is connect to the itemDoubleClicked signal from the QTableWidget, like so:



          def editItem(item):
          print 'editing', item.text()

          # initialize a table widget somehow
          table = QTableWidget(parent)
          table.setRowCount(1)
          table.setColumnCount(1)

          # create an item
          item = QTableWidgetItem('12/1/12')
          table.setItem(0, 0, item)

          # if you don't want to allow in-table editing, either disable the table like:
          table.setEditTriggers( QTableWidget.NoEditTriggers )

          # or specifically for this item
          item.setFlags( item.flags() ^ Qt.ItemIsEditable)

          # create a connection to the double click event
          table.itemDoubleClicked.connect(editItem)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 17 '12 at 17:00









          Eric Hulser

          2,9391114




          2,9391114











          • How can I make the row so that when the user clicks the row is highlighted and not the individual cell.
            – user1582983
            Aug 17 '12 at 17:22






          • 3




            do: table.setSelectionBehavior( QTableWidget.SelectRows )
            – Eric Hulser
            Aug 17 '12 at 17:27










          • Also, is there anyway that i can redirect to a different tab when a certain row is clicked? My question is can I basically redirect to a different tab, sort of like a hyperlink on a html webpage.
            – user1582983
            Aug 17 '12 at 17:53










          • Redirect or move to a tab when a button is clicked? Any ideas.
            – user1582983
            Aug 17 '12 at 20:17






          • 2




            You're setting it on the wrong widget - QWidget's don't have that property. I'm assuming if you are trying to set a tab, then somewhere you have a Tab Widget - that's where you have to set the index value. qt-project.org/doc/qt-4.8/qtabwidget.html No offense, but I've answered your question, you're now on a new question - I'd post that if you're still having trouble with more code examples and not keep pushing this one into a new topic.
            – Eric Hulser
            Aug 20 '12 at 18:21
















          • How can I make the row so that when the user clicks the row is highlighted and not the individual cell.
            – user1582983
            Aug 17 '12 at 17:22






          • 3




            do: table.setSelectionBehavior( QTableWidget.SelectRows )
            – Eric Hulser
            Aug 17 '12 at 17:27










          • Also, is there anyway that i can redirect to a different tab when a certain row is clicked? My question is can I basically redirect to a different tab, sort of like a hyperlink on a html webpage.
            – user1582983
            Aug 17 '12 at 17:53










          • Redirect or move to a tab when a button is clicked? Any ideas.
            – user1582983
            Aug 17 '12 at 20:17






          • 2




            You're setting it on the wrong widget - QWidget's don't have that property. I'm assuming if you are trying to set a tab, then somewhere you have a Tab Widget - that's where you have to set the index value. qt-project.org/doc/qt-4.8/qtabwidget.html No offense, but I've answered your question, you're now on a new question - I'd post that if you're still having trouble with more code examples and not keep pushing this one into a new topic.
            – Eric Hulser
            Aug 20 '12 at 18:21















          How can I make the row so that when the user clicks the row is highlighted and not the individual cell.
          – user1582983
          Aug 17 '12 at 17:22




          How can I make the row so that when the user clicks the row is highlighted and not the individual cell.
          – user1582983
          Aug 17 '12 at 17:22




          3




          3




          do: table.setSelectionBehavior( QTableWidget.SelectRows )
          – Eric Hulser
          Aug 17 '12 at 17:27




          do: table.setSelectionBehavior( QTableWidget.SelectRows )
          – Eric Hulser
          Aug 17 '12 at 17:27












          Also, is there anyway that i can redirect to a different tab when a certain row is clicked? My question is can I basically redirect to a different tab, sort of like a hyperlink on a html webpage.
          – user1582983
          Aug 17 '12 at 17:53




          Also, is there anyway that i can redirect to a different tab when a certain row is clicked? My question is can I basically redirect to a different tab, sort of like a hyperlink on a html webpage.
          – user1582983
          Aug 17 '12 at 17:53












          Redirect or move to a tab when a button is clicked? Any ideas.
          – user1582983
          Aug 17 '12 at 20:17




          Redirect or move to a tab when a button is clicked? Any ideas.
          – user1582983
          Aug 17 '12 at 20:17




          2




          2




          You're setting it on the wrong widget - QWidget's don't have that property. I'm assuming if you are trying to set a tab, then somewhere you have a Tab Widget - that's where you have to set the index value. qt-project.org/doc/qt-4.8/qtabwidget.html No offense, but I've answered your question, you're now on a new question - I'd post that if you're still having trouble with more code examples and not keep pushing this one into a new topic.
          – Eric Hulser
          Aug 20 '12 at 18:21




          You're setting it on the wrong widget - QWidget's don't have that property. I'm assuming if you are trying to set a tab, then somewhere you have a Tab Widget - that's where you have to set the index value. qt-project.org/doc/qt-4.8/qtabwidget.html No offense, but I've answered your question, you're now on a new question - I'd post that if you're still having trouble with more code examples and not keep pushing this one into a new topic.
          – Eric Hulser
          Aug 20 '12 at 18:21

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12009134%2fadding-widgets-to-qtablewidget-pyqt%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kleinkühnau

          Makov (Slowakei)

          Deutsches Schauspielhaus