1

I am trying to set rowspan on second column of my QTableView but somehow logically i am missing something. i am only able to get A and B but not C. Plus i am getting warning QTableView::setSpan: span cannot overlap and QTableView::setSpan: single cell span won't be added

enter image description here

My code snippet is:-

startspan = 0
for i, tcname in enumerate(tcfilename):
    if tcfilename[i]:
        if i > 0:
            print '#######################'
            print 'startspan = '+str(startspan)+' i = '+str(i)
            if tcname == tcfilename[i-1]:
                #setSpan (row, column, rowSpan, columnSpan)
                print 'if (from_row, till_row) '+str(startspan)+'  '+str(i)
                table_view.setSpan(startspan, 1, i, 1);
            elif tcname != tcfilename[i-1]:
                print 'Else no span (from_row, till_row) '+str(startspan)+'  '+str(i)
                table_view.setSpan(startspan, 1, i, 1);
                if i == 1:
                    startspan = 0
                else:
                    startspan = i
    else:
        break
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Pawankumar Dubey
  • 387
  • 1
  • 6
  • 21

2 Answers2

0

Did this with simple two line code below

for toRow, tcname in enumerate(tcfilename):
    table_view.setSpan(tcfilename.index(tcname), 1, tcfilename.count(tcname), 1)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Pawankumar Dubey
  • 387
  • 1
  • 6
  • 21
0

I made a nifty little function to solve this.. Had recursion but then optimized it without recursion.. feed it a table and a data set

def my_span_checker(self, my_data, table):

for i in range(len(my_data)):
    my_item_count = 0
    my_label = table.item(i, 0).text()
    for j in range(len(my_data)):
        if table.item(j, 0).text() == my_label:
            my_item_count += 1
    if my_item_count != 1:
        table.setSpan(i, 0, my_item_count, 1)
Josep Bigorra
  • 733
  • 2
  • 9
  • 20