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. Remove user selected rows from a QTableWidget
Forum Updated to NodeBB v4.3 + New Features

Remove user selected rows from a QTableWidget

Scheduled Pinned Locked Moved General and Desktop
19 Posts 3 Posters 41.0k 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
    panosk
    wrote on last edited by
    #10

    [quote author="SatelliteEyes" date="1364333501"]This edit gives me the error: TypeError: remove() takes exactly 1 argument (0 given). If it matters, this error occurs after I open the GUI, select a row and click "Delete".[/quote]

    I tested the code before posting and it's working just fine on my setup. Are you importing the correct modules? QtGui, QtCore, etc?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SatelliteEyes
      wrote on last edited by
      #11

      Yes, I'm importing both of those. The other widgets successfully use classes from both of those modules.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        panosk
        wrote on last edited by
        #12

        [quote author="SatelliteEyes" date="1364333501"]I can not use the syntax you provided for deleteButton.connect because it was introduced in a later version of PyQt. My version is 4.4.4 and I do not have the ability to upgrade because this is a work project and work tells me what version to use. My syntax work just fine for all of the other buttons, it's just less elegant.
        [/quote]

        Then fix your connection like this:
        @
        self.connect(deleteButton,QtCore.SIGNAL('clicked()'),remove)
        @

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SatelliteEyes
          wrote on last edited by
          #13

          I changed what I already had:
          @ deleteButton.connect(deleteButton,QtCore.SIGNAL('clicked()'),remove)
          @

          to:
          @ self.connect(deleteButton,QtCore.SIGNAL('clicked()'),remove)@

          and I am still getting the same error.

          I thought that it might have something to do with not specifying a receiver, so I changed things to:
          @ deleteButton.connect(deleteButton,QtCore.SIGNAL('clicked()'),qTable,remove())
          @
          This continues to give me the error that remove is not receiving arguments.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            panosk
            wrote on last edited by
            #14

            Don't know what's wrong then. The button code works fine on my setup (using PySide instead of PyQt though), with both connection styles. Anyway, here is the full code that works for me. Try to run it as is and see if the button works. Otherwise, you may have to dig deeper into your PyQt version.
            @
            class questionGUI(QtGui.QWidget):
            #This class is the window of the gui. The methods within this class
            #are the widgets that make up the different user input regions of the gui
            grid = QtGui.QGridLayout()
            grid.setSpacing(10)

            row = 3
            
            def __init__(self):
                super(questionGUI,self).__init__()
            
                self.widgetFive()
                #self.widgetFour()
                self.widgetThree()
                self.widgetTwo()
                self.widgetOne()
                
            
            def widgetOne(self):
                qTable = QtGui.QTableWidget(self.row,1)
                qTableName = QtGui.QLabel('Available Questions')
                entries = ['[Pick Image] <Default>','[Slider Question] <Default>', '[Comment Box] <Default>']
            
                addrow = 0
                for i in entries:
                    item = QtGui.QTableWidgetItem(i)
                    qTable.setItem(addrow,0,item)
                    addrow += 1
               
                qTable.State(2)
            
                def remove():
                    rows = qTable.selectionModel().selectedRows()
                    for r in rows:
                        qTable.removeRow(r.row())
            
                deleteButton = QtGui.QPushButton('Delete',self)
                self.connect(deleteButton,QtCore.SIGNAL('clicked()'),remove)
            
                qTable.setColumnWidth(0,300)
            
                self.grid.addWidget(qTableName,1,0)
                self.grid.addWidget(qTable,2,0, 1, 2)
                self.grid.addWidget(deleteButton,3,0)
            
            def widgetTwo(self):
                #this widget is composed of a pulldown menu with the different question type options.
                qType = QtGui.QLabel('Type')
                qTypeMenu = QtGui.QComboBox()
                qTypeMenu.addItem('[Pick Image] <customtext>')
                qTypeMenu.addItem('[Slider Question] <customtext>')
                qTypeMenu.addItem('[Comment Box] <customtext>')
            
                self.grid.addWidget(qType, 4, 0)
                self.grid.addWidget(qTypeMenu,4,1)
            
            def widgetThree(self):
                #this widget allows you to edit the Question text and the Tab text.
                qText = QtGui.QLabel('Question Text')
                qTextEntry = QtGui.QLineEdit()
                tText = QtGui.QLabel('Tab Text')
                tTextEntry = QtGui.QLineEdit()
            
                self.grid.addWidget(qText, 5,0)
                self.grid.addWidget(qTextEntry, 5, 1)
                self.grid.addWidget(tText, 6, 0)
                self.grid.addWidget(tTextEntry, 6, 1)
            
            def widgetFive(self):
                addQuestionButton = QtGui.QPushButton('Add Question',self)
                addQuestionButton.connect(addQuestionButton,QtCore.SIGNAL('clicked()'),QtGui.qApp, QtCore.SLOT('quit()'))
                addQuestionButton.resize(addQuestionButton.sizeHint())
            
               
                doneButton = QtGui.QPushButton('Done',self)
                doneButton.connect(doneButton,QtCore.SIGNAL('clicked()'),QtGui.qApp, QtCore.SLOT('quit()'))
                doneButton.resize(doneButton.sizeHint())
            
                self.grid.addWidget(addQuestionButton,7,0)
                self.grid.addWidget(doneButton,7,1)
            
                self.setLayout(self.grid)
            
                self.setGeometry(300,300,400,500)
                self.setWindowTitle('Question Editor')
                self.show()
            

            def main():
            app = QtGui.QApplication(sys.argv)
            ex = questionGUI()
            sys.exit(app.exec_())

            if name == 'main':
            main()
            @

            1 Reply Last reply
            0
            • P Offline
              P Offline
              panosk
              wrote on last edited by
              #15

              And one more older connection style to try out :-)
              @
              QtCore.QObject.connect(deleteButton,QtCore.SIGNAL('clicked()'),remove)
              @

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SatelliteEyes
                wrote on last edited by
                #16

                Thanks for your help yesterday. After all this, I'm pretty sure it has to be a version problem. Your code is still giving me the 'not enough arguments' error.

                Just to be safe, I change my table to a list, thinking that maybe a simpler widget wouldn't have the problem, but it does. I think I'm going to give up on this and find someone at my company to debug it the rest of the way with me. Thanks,again.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SatelliteEyes
                  wrote on last edited by
                  #17

                  I've made progress! I'm not sure if you're still interested, but here is the development. I'm using QtCore.SIGNAL('itemClicked(clicked)') as the signal, rather than the regular QtCore.SIGNAL('clicked()'). This still does not delete the line, but it is not giving me the 'no arguments' error. A new error is always good!

                  Now, when I select a row, the selection is blue. When I click the Delete button, the selection color (not the text, the background color in the selected cell) turns grey. You don't have to respond to this, I'll beat on this some more and post a new discussion if I get stuck.

                  Here is the new code:

                  @
                  def widgetOne(self):
                  def questionMoved(self,indexes):
                  print indexes

                      qList = QtGui.QListWidget(self)
                      qList.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
                      qList.connect(qList,QtCore.SIGNAL('indexesMoved(const QModelIndexList&)'),questionMoved)
                  
                      qListName = QtGui.QLabel('Available Questions')
                      entries = ['[Pick Image] <Default>','[Slider Question] <Default>', '[Comment Box] <Default>']
                  
                      for i in entries:
                          item = QtGui.QListWidgetItem(i)
                          qList.addItem(item)
                      
                      def deleteLink(self):
                          self._sql.delete()
                          self._sql = None
                  
                      def remove(self):
                          #hopefully this will let the Delete button remove the selected table row
                          row = qList.currentRow()
                          if (row<0): return
                  
                          item = qList.takeItem(row)
                          item.deleteLink()
                  
                          for r in range(row, qList.count()):
                              item = qList.item(r)
                              item.setOrder(row)
                              row += 1
                      
                      clicked = qList.currentRow()
                      deleteButton = QtGui.QPushButton('Delete',self)
                      deleteButton.connect(deleteButton,QtCore.SIGNAL('itemClicked(clicked)'),remove)
                  
                      self.grid.addWidget(qListName,1,0)
                      self.grid.addWidget(qList,2,0, 1, 2)
                      self.grid.addWidget(deleteButton,3,0)
                  

                  @

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    panosk
                    wrote on last edited by
                    #18

                    Hi there,

                    In case you haven't already seen this, have a look at this page http://pyqt.sourceforge.net/Docs/PyQt4/old_style_signals_slots.html#pyqt4-signals-and-qt-signals

                    My advice though would be to convince your team to use a more recent version of PyQt (or use PySide) :-)

                    1 Reply Last reply
                    0
                    • Jimmy CrabJ Offline
                      Jimmy CrabJ Offline
                      Jimmy Crab
                      wrote on last edited by
                      #19
                      This post is deleted!
                      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