【问题标题】:adding a header to pyqt list向 pyqt 列表添加标题
【发布时间】:2010-05-01 10:10:31
【问题描述】:

我想在 pyqt 中的列表中添加标题和索引,QT 列表(qlistwidget、qlistview、qtablewidget、qtreeview)真的不重要

简而言之..我想要pyqt演示中的旋转框委托示例...... 但我想要一个字符串而不是列标题中的索引...



希望这个想法足够清楚
提前谢谢

【问题讨论】:

    标签: python qt pyqt pyqt4


    【解决方案1】:

    QTableWidget 可能是您的最佳选择 - 它使用setHorizontalHeaderLabels()setVerticalHeaderLabels() 让您控制两个轴。

    from PyQt4 import QtGui
    
    class MyWindow(QtGui.QMainWindow):
    
        def __init__(self, parent):
            QtGui.QMainWindow.__init__(self, parent)
    
            table = QtGui.QTableWidget(3, 3, self)  # create 3x3 table
            table.setHorizontalHeaderLabels(('Col 1', 'Col 2', 'Col 3'))
            table.setVerticalHeaderLabels(('Row 1', 'Row 2', 'Row 3'))
            for column in range(3):
                for row in range(3):
                    table.setItem(row, column, QtGui.QWidget(self))  # your contents
    
            self.setCentralWidget(table)
            self.show()
    

    当然,如果您想完全控制标题的内容和格式,那么您可以使用 .setHorizo​​ntalHeaderItem() 和 .setVerticalHeaderItem() 方法为每个标题定义一个 QTableWidgetItem...

    详情请参阅official documentation

    【讨论】:

      猜你喜欢
      • 2018-10-22
      • 2013-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多