简体   繁体   English

QTableView项目在PyQt 5.8和5.9中的绘制方式有所不同

[英]QTableView items was draw differently in PyQt 5.8 and 5.9

It happened when I use the following code on win7 32bit, 当我在win7 32bit上使用以下代码时,

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


if __name__ == '__main__':

    app = QApplication(sys.argv)
    # ui = QMainWindow()

    path = r'D:\BaiduYunDownload\untitled'
    model = QFileSystemModel()
    model.setRootPath(path)

    table = QTableView()
    table.setModel(model)
    table.setRootIndex(model.index(path))

    # ui.setCentralWidget(table)
    table.resize(800, 600)
    table.show()

    viewOptions = table.viewOptions()
    print(table.wordWrap(),
          int(viewOptions.textElideMode),
          int(viewOptions.decorationAlignment),
          int(viewOptions.displayAlignment),
          int(viewOptions.features))

    app.exec_()

there is only one file with the long name(for test): A directory model that displays the contents of a default directory is usually constructed with a parent object.txt in dir D:\\BaiduYunDownload\\untitled 只有一个长名称的文件(用于测试): A directory model that displays the contents of a default directory is usually constructed with a parent object.txt在目录D:\\BaiduYunDownload\\untitled

In PyQt 5.8 (installed via pip3 install pyqt5==5.8 ) 在PyQt 5.8中(通过pip3 install pyqt5==5.8 在此处输入图片说明

In PyQt 5.9.1 (installed via pip3 install pyqt5==5.9 ) 在PyQt 5.9.1中(通过pip3 install pyqt5==5.9 在此处输入图片说明

I wonder why the QTableView item in the Name column was draw differently ? 我想知道为什么“ Name列中的QTableView项绘制的方式有所不同? I checked with the following property in the code, all returned the same value in both version of PyQt . 我在代码中检查了以下属性,在两个版本的PyQt中都返回了相同的值。

print(table.wordWrap(),
int(viewOptions.textElideMode),
int(viewOptions.decorationAlignment),
int(viewOptions.displayAlignment),
int(viewOptions.features))

That appears to be a Qt bug. 那似乎是Qt的错误。 Check out Qt's bug report here . 在此处查看Qt的错误报告。

One workaround consists in setting font properties via CSS. 一种解决方法是通过CSS设置字体属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM