相关疑难解决方法(0)

PyQt - 如何使用QItemDelegate在表视图中设置QComboBox

我试图在我的表中显示一个组合框,以便我可以从表模型中设置所选索引,就像表中的其他单元格一样.我已经从其他示例拼凑了这些,但仍然无法理解交互如何工作来设置QComboBox的选定索引.

这是我能用来证明问题的最简单的例子.如果有人能演示如何从模型数据中自动设置索引?另外如何使用'currentIndexChanged'信号,因为这似乎在重新绘制时几乎连续不断?谢谢.

# The following tells SIP (the system that binds Qt's C++ to Python)
# to return Python native types rather than QString and QVariant
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)


from PyQt4 import QtCore, QtGui

class TableModel(QtCore.QAbstractTableModel):
    """
    A simple 5x4 table model to demonstrate the delegates
    """
    def rowCount(self, parent=QtCore.QModelIndex()): return 5
    def columnCount(self, parent=QtCore.QModelIndex()): return 4

    def data(self, index, role=QtCore.Qt.DisplayRole):
        if not index.isValid(): return None
        if not role==QtCore.Qt.DisplayRole: return None
        return "{0:02d}".format(index.row())


class ComboDelegate(QtGui.QItemDelegate):
    """
    A …
Run Code Online (Sandbox Code Playgroud)

python qt pyqt

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

pyqt ×1

python ×1

qt ×1