【问题标题】:PyQt QTableView with QComboBoxPyQt QTableView 与 QComboBox
【发布时间】:2011-08-20 01:46:10
【问题描述】:

我正在使用QTableView 显示来自数据库的信息。我希望将字段显示为组合框,以便用户可以轻松修改它们。 我阅读了很多关于必须将自定义委托项和标志设置为 IsUserCheckable 的内容,但我不明白所有这些应该如何工作。 我用标志和角色尝试了几件事,但完全没有效果,所以我确实错过了一些重要的事情

我真的很感激这个工作代码示例,或者如果有人手头有一个很好的解释:)

【问题讨论】:

    标签: qt combobox pyqt qtableview


    【解决方案1】:

    这里有一些示例,但如果您想要更高级的内容,请参阅 QItemDelegate Class Reference

    import sys
    from PyQt4 import QtGui, QtCore
    
    class Example(QtGui.QMainWindow):
    
        def __init__(self):
            super(Example, self).__init__()
    
            table= QtGui.QTableWidget(5, 5)
            self.setCentralWidget(table)
            combobox = QtGui.QComboBox()
            combobox.addItem('one')
            combobox.addItem('two')        
            table.setCellWidget(3, 4, combobox)
    
    
    if __name__ == '__main__':
        app = QtGui.QApplication(sys.argv)
        window = Example()
        window.setWindowTitle('ComboBox in Table Example')
        window.resize(600, 400)
        window.show()
        sys.exit(app.exec_())
    

    【讨论】:

      猜你喜欢
      • 2017-04-01
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-26
      • 2016-11-13
      • 2015-06-10
      • 1970-01-01
      相关资源
      最近更新 更多