Thursday 15 March 2012

python - Adding a combobox in my tablewidget -


I want to add a blanket box to my tablewidth cell. When I click on the cell, the combobox will appear.

This is the problem but the problem is that when I click on the cells after one, it shows that the combo box has been removed? QtGui, QtCore class Mainwin (QtGui.QWidget) from PyQt4 import: def __init __ (self, parent = none): QtGui.QWidget .__ init __ (self, parent) self.resize (

  import sys 500, 700) self.comb = QtGui.QComboBox () self.comb.addItem ("raton") self.table = QtGui.QTableWidget (self) self.table.setColumnCount (3) self.table .setRowCount (4) self.table.cellClicked.connect (self.addcomb) def addcomb (auto, line, color): self.table.setCellWidget (line, call, self.comb)   < P> What is the problem?   

One widget can not be placed in two places at a time when you put it in another cell , Then it disappears due to 1. But 1 cell does not know about it and still the ownership of the widget remains. When you click 1 cell again and call setCellWidget , it removes your previous object mentioned in the documentation. So your combobox is now lost for good.

Once you've put it on the table, there is no way to take Cambodia's ownership. So I think that every time you want to set up a cell widget, you will need to create a new combo box.

If you still want to put a single combo box in the table, you can delete the previous combo box before creating a new one:

  self.old_row = - 1 self.old_col = -1 def addcomb (auto, line, color): if self.old_row> = 0: self.table.setCellWidget (self.old_row, self.old_col, none) self.old_row = line self.old_col = col comb = QtGui.QComboBox () comb. IdITem ("rattan") self.table.setCellWidget (line, call, comb)    

No comments:

Post a Comment