PyQt4 code not working on PyQt5 (QHeaderView)

后端 未结 2 397
礼貌的吻别
礼貌的吻别 2021-01-05 01:11

I was using PyQt4 and this code works great.

self.table.horizontalHeader().setResizeMode(1, QHeaderView.Stretch)

It\'s stretching a column

相关标签:
2条回答
  • 2021-01-05 01:38

    In PyQt5 should be:

    header = self.table.horizontalHeader()       
    header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
    header.setSectionResizeMode(1, QtWidgets.QHeaderView.ResizeToContents)
    header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
    
    0 讨论(0)
  • 2021-01-05 01:51

    Use QHeaderView.setSectionResizeMode instead of QHeaderView.setResizeMode:

    Use setSectionResizeMode instead.

    (Quote from documentation for QHeaderView.setResizeMode)

    0 讨论(0)
提交回复
热议问题