我想从Righ更改Qtablewidget的方向

2024-04-26 18:36:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要让Qtablewidget从右到左开始,也就是说右边的verticalHeader()

    self.table = QTableWidget()
    self.table.setGeometry(0 , 0 , 700 , 700)
    self.table.setColumnCount(4)
    self.table.setRowCount(30)
    self.table.setHorizontalHeaderLabels(['يومى', 'الاسبوع' , 'الشهرى' , 'المادة'])
    self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

enter image description here


Tags: selftablestretchqtablewidgetsetgeometryqheaderviewhorizontalheadersetrowcount
1条回答
网友
1楼 · 发布于 2024-04-26 18:36:52

layoutDirection : Qt::LayoutDirection

This property holds the default layout direction for this application

On system start-up, the default layout direction depends on the application's language.

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore    import *

class MyWin(QMainWindow):
    def __init__(self, parent=None):
        super(MyWin, self).__init__()
        central_widget = QWidget()
        self.setCentralWidget(central_widget)

        self.table = QTableWidget(central_widget)
        self.table.setGeometry(0 , 0 , 700 , 700)
        self.table.setColumnCount(4)
        self.table.setRowCount(30)
        self.table.setHorizontalHeaderLabels(['يومى1', 'الاسبوع2' , 'الشهرى3' , 'المادة4'])
        self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setLayoutDirection(Qt.RightToLeft)           # <         -
    w = MyWin()
    w.resize(700, 700)
    w.show()
    sys.exit(app.exec_())

enter image description here

相关问题 更多 >