مندوب البند مخصص Pyqt ل QtableWidget
سؤال
لدي QtableWidget مع 5 أعمدة فيها، كيف يمكنني تعيين جميع العناصر في العمود 2 ليكون QPRogressBar؟
حاولت شيئا مثل:
self.downloads_table = QtGui.QTableWidget(0, 5)
self.downloads_table.setItemDelegateForColumn(2, DownloadDelegate(self))
حيث DownloaddLegate هو:
class DownloadDelegate(QItemDelegate):
def __init__(self, parent=None):
super(DownloadDelegate, self).__init__(parent)
def createEditor(self, parent, option, index):
return QProgressBar(parent)
لكن شريط التقدم لا يظهر على الإطلاق. اي فكرة؟
المحلول
كما قال ماركوني،
QTableWidget.setCellWidget(row, column, QWidget)
يضيف qwidget إلى الخلية في (الصف، العمود) ويعطيها QtableWidget كوالد.
على سبيل المثال شيء على طول هذه الخطوط:
table = QTableWidget(1, 3)
item1 = QTableWidgetItem("foo")
comboBox = QComboBox()
checkBox = QCheckBox()
table.setItem(0,0,item1)
table.setCellWidget(0,1,comboBox)
table.setCellWidget(0,2,checkBox)
سوف أعطيك 1x3
جدول مع "foo" في cell 0,0
, ، أ QComboBox
في cell 0,1
و QCheckBox
في cell 0,2
.
نصائح أخرى
يجب أن يعود النموذج itemEditable
في flags()
لا تنتمي إلى StackOverflow