python 3.x - Dynamically created tablewidget -


i have function dynamically creates stackedwidget , adds new pages based on query. each page gets dynamically created tablewidget loaded before code loops again. stackedwidget controlled list filled @ same time each page created. point, works great having problem extracting data tablewidgets. @ end of loops there signal

ui.tablewidget.cellchanged[int,int].connect(savelineitem) 

that used testing. function savelineitem print row & column whichever tablewidget clicked on, last line, print text, print last tablewidget created. signal recognizes current tablewidget. how can pass on savelineitem function?

    def savelineitem(row, col):         print('row = ' + str(row))        print('column = ' + str(col))        ui = uidef.ui        print(ui.tablewidget.item(row, col).text())      def loadinventory(ui):             conn = sqlite3.connect('dblocal.sqlite')             cur = conn.cursor()              sql = "select inventory.inventory inventory description = '*' order display_no"             cur.execute(sql)             rows = cur.fetchall()              if ui.swinventory:                 ui.swinventory.close()             ui.lstcatagory.clear()             ui.swinventory = qtwidgets.qstackedwidget(ui.tab_inventory)             ui.swinventory.setgeometry(qtcore.qrect(255, 20, 876, 586))             ui.swinventory.setframeshape(qtwidgets.qframe.box)             ui.swinventory.setobjectname("swinventory")             lstinvheader = ['display_no','item_no', 'trigger', 'quantity', 'description', 'part_no', 'price', 'inventory', 'spreadsheet', 'nodisplay', 't_s', 'track', 'msg', 's_hooks', 'p_hooks' ]             row in rows:                 scatname = row[0]                 page = scatname                 ui.lstcatagory.additem(scatname)                 ui.page = qtwidgets.qwidget()                 ui.page.setobjectname(scatname)                 ui.tablewidget = qtwidgets.qtablewidget(ui.page)                 ui.tablewidget.setgeometry(qtcore.qrect(20, 20, 831, 561))                 font = qtgui.qfont()                 font.setpointsize(14)                 ui.tablewidget.setfont(font)                 ui.tablewidget.setalternatingrowcolors(true)                         ui.tablewidget.setobjectname("tablewidget")                 ui.tablewidget.setrowcount(1)                 ui.tablewidget.verticalheader().setvisible(false)                  ui.tablewidget.setcolumncount(15)                 ui.tablewidget.sethorizontalheaderlabels(lstinvheader)                 ui.tablewidget.hidecolumn(0)                 ui.tablewidget.hidecolumn(1)                 ui.tablewidget.hidecolumn(2)                 ui.tablewidget.hidecolumn(5)                 ui.tablewidget.hidecolumn(7)                 ui.tablewidget.hidecolumn(8)                 ui.tablewidget.hidecolumn(9)                 ui.tablewidget.hidecolumn(10)                 ui.tablewidget.hidecolumn(11)                 ui.tablewidget.hidecolumn(12)                 ui.tablewidget.hidecolumn(13)                 ui.tablewidget.hidecolumn(14)                 ui.tablewidget.setcolumnwidth(4, 611)                  sql = "select * inventory inventory = '{}' order display_no".format(scatname)                 cur.execute(sql)                 invrows = cur.fetchall()                 = 0                 row in invrows:                     if row[4] == '*':                         pass                     else:                         rdisplay_no = str(row[0])                         iitem_no = str(row[1])                         itrigger = str(row[2])                         iquantity = ""                         if row[3] == none:                             iquantity = ""                         else:                             #iquantity = round(row[6], 2)                                            iquantity = str(iquantity)                         sdescription = " " + str(row[4])                         spart_no = row[5]                         rprice = str(row[6])                         sinventory = row[7]                         sspreadsheet = row[8]                         inodisplay = str(row[9])                         it_s = str(row[10])                         itrack = str(row[11])                         imsg = str(row[12])                         is_hooks = str(row[13])                         ip_hooks = str(row[14])                          item = qtablewidgetitem(rdisplay_no)                         item2 =  qtablewidgetitem(iitem_no)                         item3 =  qtablewidgetitem(itrigger)                         item4 = qtablewidgetitem(iquantity)                         item5 =  qtablewidgetitem(sdescription)                         item6 =  qtablewidgetitem(spart_no)                         item7 = qtablewidgetitem(rprice)                         item8 =  qtablewidgetitem(sinventory)                         item9 =  qtablewidgetitem(sspreadsheet)                         item10 = qtablewidgetitem(inodisplay)                          item11 =  qtablewidgetitem(it_s)                         item12 =  qtablewidgetitem(itrack)                         item13 = qtablewidgetitem(imsg)                         item14 =  qtablewidgetitem(is_hooks)                         item15 =  qtablewidgetitem(ip_hooks)                          item4.settextalignment(qt.aligncenter)                         item5.setflags( qt.noitemflags | qt.itemisenabled)                         item7.setflags( qt.itemisselectable | qt.itemisenabled)                          ui.tablewidget.setitem(i,0, item)                         ui.tablewidget.setitem(i,1, item2)                         ui.tablewidget.setitem(i,2, item3)                         ui.tablewidget.setitem(i,3, item4)                         ui.tablewidget.setitem(i,4, item5)                         ui.tablewidget.setitem(i,5, item6)                         ui.tablewidget.setitem(i,6, item7)                         ui.tablewidget.setitem(i,7, item8)                         ui.tablewidget.setitem(i,8, item9)                         ui.tablewidget.setitem(i,9, item10)                         ui.tablewidget.setitem(i,10, item11)                         ui.tablewidget.setitem(i,11, item12)                         ui.tablewidget.setitem(i,12, item13)                         ui.tablewidget.setitem(i,13, item14)                         ui.tablewidget.setitem(i,14, item15)                         += 1                         ui.tablewidget.setrowcount(i+2)                  setattr(uidef, "ui", ui)                     ui.tablewidget.cellchanged[int,int].connect(savelineitem)                 ui.label = qtwidgets.qlabel(ui.page)                 ui.label.setgeometry(qtcore.qrect(308, 0, 151, 20))                 ui.label.setalignment(qtcore.qt.aligncenter)                 ui.label.setobjectname("label")                 ui.label.settext(scatname)                 ui.swinventory.addwidget(ui.page)             inumpages = ui.swinventory.count() 

the usual way solve kind of problem connect signal lambda (or partial function) caches reference current object:

def savelineitem(table, row, col):    print('row = ' + str(row))    print('column = ' + str(col))    print(table.item(row, col).text())  def loadinventory(ui):     ...     ui.tablewidget.cellchanged[int,int].connect(         lambda row, colum, table=ui.tablewidget:             savelineitem(table, row, column)) 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -