Я создал собственный скрипт, который отлично работает на основе предыдущего ответа.
скопируйте и вставьте следующий код в файл rotated.py
#!/usr/bin/env python
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class RotatedHeaderView(QHeaderView):
def __init__(self, parent=None):
super(RotatedHeaderView, self).__init__(Qt.Horizontal, parent)
self.setMinimumSectionSize(20)
def paintSection(self, painter, rect, logicalIndex ):
painter.save()
# translate the painter such that rotate will rotate around the correct point
painter.translate(rect.x()+rect.width(), rect.y())
painter.rotate(90)
# and have parent code paint at this location
newrect = QRect(0,0,rect.height(),rect.width())
super(RotatedHeaderView, self).paintSection(painter, newrect, logicalIndex)
painter.restore()
def minimumSizeHint(self):
size = super(RotatedHeaderView, self).minimumSizeHint()
size.transpose()
return size
def sectionSizeFromContents(self, logicalIndex):
size = super(RotatedHeaderView, self).sectionSizeFromContents(logicalIndex)
size.transpose()
return size
затем импортируйте из вашего файла main.py этот класс, используя следующую строку:
from rotated import RotatedHeaderView
и выполните действия с этой строкой:
self.YourTableName.setHorizontalHeader(RotatedHeaderView(self.YourTableName))
надежда того стоит!