title: Python - QTableWidget.selectedRanges() return multiple ranges for on selection
body: <p>I'm new in python and develop a GUI with a table. It should be possible to connect rows and column via a context menu. And this works. 
  I can selected multiple rows by using ctrl + mouse left click.</p>
  
  <p>But is one or more span is/are in the table and i want to add more, QTableWidget.selectedRanges() returns <strong>n*m</strong> selectionRanges if if select a nXm selection.
  For example if i selected 3 rows in a column, there are 3 selectionRanges.</p>
  
  <p>And on the console is written 3 times</p>
  
  <pre><code>QTableView::setSpan: single cell span won't be added 
  </code></pre>
  
  <p>Python 2.7.5+ is installed.</p>
  
  <p>Thx and bye.</p>
  
  <p><strong>Edited on 17th March 2014</strong></p>
  
  <p>Here is the complete code of my small program.</p>
  
  <p>The program.py</p>
  
  <pre><code>import sys
  from PyQt4 import QtGui, QtCore
  from tableGui import Ui_Dialog as Dlg
  
  
  class MarkDownTableGui(QtGui.QDialog,Dlg):
    def __init__(self):
      QtGui.QDialog.__init__(self)
      self.setupUi(self)
      ColumnCount = None
      ColumnRow = None    
      # Context menu connect cell/reset connected/selected cells
      self.menu = QtGui.QMenu()           
      self.menu.addAction("Connect",self.addSpan)
      self.menu.addAction("Reset",self.resetConnected)     
  
      self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
  
      self.customContextMenuRequested.connect(self.showContextMenu)            
      self.connect(self.generateButton,QtCore.SIGNAL("clicked()"),self.onGenerate)
  
    def onGenerate(self):    
      """
        Generate a m x n table
      """
      self.tableWidget.setRowCount(self.RowCount.value())
      self.tableWidget.setColumnCount(self.ColumnCount.value())
  
    def addSpan(self):    
      selectedElements = self.tableWidget.selectedRanges()       
  
      for slrange in selectedElements:      
        self.tableWidget.setSpan(slrange.topRow(),slrange.leftColumn(),slrange.rowCount(),slrange.columnCount())  
  
  
    def showContextMenu(self,pos):             
      self.menu.exec_(QtGui.QCursor.pos())    
  
    def resetConnected(self):
      #TODO
      print "TODO"
  
  
  app = QtGui.QApplication(sys.argv)
  dialog = MarkDownTableGui()
  dialog.show()
  sys.exit(app.exec_())
  </code></pre>
  
  <p>this is the tableGui.py, generated by pyuic4</p>
  
  <pre><code># -*- coding: utf-8 -*-
  
  # Form implementation generated from reading ui file 'dialog_Table.ui'
  #
  # Created: Mon Mar 17 08:59:43 2014
  #      by: PyQt4 UI code generator 4.10.3
  #
  # WARNING! All changes made in this file will be lost!
  
  from PyQt4 import QtCore, QtGui
  
  try:
      _fromUtf8 = QtCore.QString.fromUtf8
  except AttributeError:
      def _fromUtf8(s):
          return s
  
  try:
      _encoding = QtGui.QApplication.UnicodeUTF8
      def _translate(context, text, disambig):
          return QtGui.QApplication.translate(context, text, disambig, _encoding)
  except AttributeError:
      def _translate(context, text, disambig):
          return QtGui.QApplication.translate(context, text, disambig)
  
  class Ui_Dialog(object):
      def setupUi(self, Dialog):
          Dialog.setObjectName(_fromUtf8("Dialog"))
          Dialog.setWindowModality(QtCore.Qt.ApplicationModal)
          Dialog.resize(509, 426)
          Dialog.setModal(True)
          self.buttonBox = QtGui.QDialogButtonBox(Dialog)
          self.buttonBox.setGeometry(QtCore.QRect(140, 370, 341, 32))
          self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
          self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
          self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
          self.ColumnCount = QtGui.QSpinBox(Dialog)
          self.ColumnCount.setGeometry(QtCore.QRect(90, 10, 51, 23))
          self.ColumnCount.setMinimum(1)
          self.ColumnCount.setProperty("value", 5)
          self.ColumnCount.setObjectName(_fromUtf8("ColumnCount"))
          self.labelChapterCount = QtGui.QLabel(Dialog)
          self.labelChapterCount.setGeometry(QtCore.QRect(10, 10, 74, 23))
          self.labelChapterCount.setObjectName(_fromUtf8("labelChapterCount"))
          self.RowCount = QtGui.QSpinBox(Dialog)
          self.RowCount.setGeometry(QtCore.QRect(250, 10, 51, 23))
          self.RowCount.setMinimum(1)
          self.RowCount.setProperty("value", 5)
          self.RowCount.setObjectName(_fromUtf8("RowCount"))
          self.labelChapterCount_2 = QtGui.QLabel(Dialog)
          self.labelChapterCount_2.setGeometry(QtCore.QRect(160, 10, 74, 23))
          self.labelChapterCount_2.setObjectName(_fromUtf8("labelChapterCount_2"))
          self.generateButton = QtGui.QPushButton(Dialog)
          self.generateButton.setGeometry(QtCore.QRect(340, 10, 111, 24))
          self.generateButton.setObjectName(_fromUtf8("generateButton"))
          self.tableWidget = QtGui.QTableWidget(Dialog)
          self.tableWidget.setGeometry(QtCore.QRect(0, 40, 491, 321))
          self.tableWidget.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
          self.tableWidget.setRowCount(5)
          self.tableWidget.setColumnCount(5)
          self.tableWidget.setObjectName(_fromUtf8("tableWidget"))
  
          self.retranslateUi(Dialog)
          QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), Dialog.accept)
          QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject)
          QtCore.QMetaObject.connectSlotsByName(Dialog)
  
      def retranslateUi(self, Dialog):
          Dialog.setWindowTitle(_translate("Dialog", "Table editor", None))
          self.labelChapterCount.setText(_translate("Dialog", "Column", None))
          self.labelChapterCount_2.setText(_translate("Dialog", "Rows", None))
          self.generateButton.setText(_translate("Dialog", "generate Table", None))
  </code></pre>
  
  <p><strong>The problem</strong> </p>
  
  <ol>
  <li>if the programm is running you can select cell by pressing and holding the left mouse button</li>
  <li>Left click open the context menu</li>
  <li>Select connect, create a column/row span</li>
  <li><p>if i want to add additional spans and start at point 1. again then i got the message</p>
  
  <p>QTableView::setSpan: single cell span won't be added</p></li>
  </ol>
  
  <p>The Question is why selectedRanges() returns a list with <em>n</em> selectionRanges instead of only on selectionRange. I've read the documentation of <a href="http://qt-project.org/doc/qt-4.7/qtablewidget.html" rel="nofollow">QTableWidget</a> and <a href="http://qt-project.org/doc/qt-4.7/qtablewidgetselectionrange.html" rel="nofollow">QTableSelectionRange</a>. But haven't any ideas</p>