title: How to select QTableView row with one click
body: <p>When one of the <code>QTableView</code>'s <code>QModelIndex</code> is clicked I want to select an entire row of the same-row-indexes.</p>
  
  <p>To accomplish this I connect <code>QTableView</code>'s <code>clicked</code> signal to a custom <code>viewClicked()</code> method which receives the clicked QModelIndex automatically:</p>
  
  <pre><code>self.tableview=QTableView()
  self.tableview.clicked.connect(self.viewClicked)
  </code></pre>
  
  <p>Inside of <code>viewClicked(self, clickedIndex)</code> I query <code>clickedIndex</code>'s row number, its model and the total number of columns):</p>
  
  <pre><code>    row=clickedIndex.row()
      model=clickedIndex.model()
      columnsTotal=model.columnCount(None)
  </code></pre>
  
  <p>Finally to select an every index in a row:</p>
  
  <pre><code>for i in range(columnsTotal): self.tableview.selectRow(row) 
  </code></pre>
  
  <p>The problem is it is noticeably slow for Qt to process such an action.
  I wonder if there is a faster way to select an entire row of indexes  when one of the tableview items is clicked:</p>
  
  <p><img src="https://i.stack.imgur.com/pCq0H.png" alt="enter image description here"></p>
  
  <pre><code>from PyQt4.QtCore import *
  from PyQt4.QtGui import *
  import sys
  
  class Model(QAbstractTableModel):
      def __init__(self, parent=None, *args):
          QAbstractTableModel.__init__(self, parent, *args)
          self.items = ['Row0_Column0','Row0_Column1','Row0_Column2']
  
      def flags(self, index):
          return Qt.ItemIsEnabled | Qt.ItemIsSelectable
  
      def rowCount(self, parent):
          return 1      
      def columnCount(self, parent):
          return len(self.items)  
  
      def data(self, index, role):
          if not index.isValid(): return QVariant()
          elif role != Qt.DisplayRole:
              return QVariant()
  
          column=index.column()
          if column&lt;len(self.items):
              return QVariant(self.items[column])
          else:
              return QVariant()
  
  class MyWindow(QWidget):
      def __init__(self, *args):
          QWidget.__init__(self, *args)
  
          tablemodel=Model(self)               
  
          self.tableview=QTableView() 
          self.tableview.setModel(tablemodel)
          self.tableview.clicked.connect(self.viewClicked)
  
          layout = QHBoxLayout(self)
          layout.addWidget(self.tableview)
  
          self.setLayout(layout)
  
      def viewClicked(self, clickedIndex):
          row=clickedIndex.row()
          model=clickedIndex.model()
          columnsTotal=model.columnCount(None)
          for i in range(columnsTotal):
              self.tableview.selectRow(row)
  
  if __name__ == "__main__":
      app = QApplication(sys.argv)
      w = MyWindow()
      w.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <h1>EDITED LATER: REVISED WORKING CODE Thanks to Nejat! :</h1>
  
  <pre><code>from PyQt4.QtCore import *
  from PyQt4.QtGui import *
  import sys
  
  class Model(QAbstractTableModel):
      def __init__(self, parent=None, *args):
          QAbstractTableModel.__init__(self, parent, *args)
          self.items = ['Row0_Column0','Row0_Column1','Row0_Column2']
  
      def flags(self, index):
          return Qt.ItemIsEnabled | Qt.ItemIsSelectable
  
      def rowCount(self, parent):
          return 1      
      def columnCount(self, parent):
          return len(self.items)  
  
      def data(self, index, role):
          if not index.isValid(): return QVariant()
          elif role != Qt.DisplayRole:
              return QVariant()
  
          column=index.column()
          if column&lt;len(self.items):
              return QVariant(self.items[column])
          else:
              return QVariant()
  
  class MyWindow(QWidget):
      def __init__(self, *args):
          QWidget.__init__(self, *args)
  
          tablemodel=Model(self)               
  
          self.tableview=QTableView() 
          self.tableview.setModel(tablemodel)
          self.tableview.clicked.connect(self.viewClicked)
  
          self.tableview.setSelectionBehavior(QTableView.SelectRows)
  
          layout = QHBoxLayout(self)
          layout.addWidget(self.tableview)
  
          self.setLayout(layout)
  
      def viewClicked(self, clickedIndex):
          row=clickedIndex.row()
          model=clickedIndex.model()
  
  if __name__ == "__main__":
      app = QApplication(sys.argv)
      w = MyWindow()
      w.show()
      sys.exit(app.exec_())
  </code></pre>