zhiyiYo / PyQt-Fluent-Widgets

A fluent design widgets library based on C++ Qt/PyQt/PySide. Make Qt Great Again.
https://qfluentwidgets.com
GNU General Public License v3.0
5.61k stars 541 forks source link

[Bug]: 运行readme提到的examples/gallery/demo.py报错 #718

Closed 3293406747 closed 9 months ago

3293406747 commented 9 months ago

What happened?

我下载的pyside2版本的代码,运行examples/gallery/demo.py报错了。

FIXME Subscripted generics cannot be used with class and instance checks
Traceback (most recent call last):
  File "c:\Users\Administrator\Downloads\PyQt-Fluent-Widgets-PySide2\examples\gallery\demo.py", line 39, in <module>
    w = MainWindow()
  File "c:\Users\Administrator\Downloads\PyQt-Fluent-Widgets-PySide2\examples\gallery\app\view\main_window.py", line 36, in __init__
    super().__init__()
  File "D:\anaconda3\envs\py38\lib\site-packages\qfluentwidgets\window\fluent_window.py", line 150, in __init__
    super().__init__(parent)
  File "D:\anaconda3\envs\py38\lib\site-packages\qfluentwidgets\window\fluent_window.py", line 27, in __init__
    super().__init__(parent=parent)
  File "D:\anaconda3\envs\py38\lib\site-packages\qfluentwidgets\common\animation.py", line 85, in __init__
    self.bgColorObject = BackgroundColorObject(self)
  File "D:\anaconda3\envs\py38\lib\site-packages\qfluentwidgets\common\animation.py", line 171, in __init__
    super().__init__(parent)
TypeError: 'PySide2.QtCore.QObject' called with wrong argument types:
  PySide2.QtCore.QObject(MainWindow)
Supported signatures:
  PySide2.QtCore.QObject(typing.Union[PySide2.QtCore.QObject, NoneType] = None)

image

Operation System

Windows10

Python Version

3.8.18

PyQt/PySide Version

Pyside2 5.15.2.1

PyQt/PySide-Fluent-Widgets Version

1.4.6

How to Reproduce?

我下载的pyside2版本的代码,运行examples/gallery/demo.py报错了。

FIXME Subscripted generics cannot be used with class and instance checks
Traceback (most recent call last):
  File "c:\Users\Administrator\Downloads\PyQt-Fluent-Widgets-PySide2\examples\gallery\demo.py", line 39, in <module>
    w = MainWindow()
  File "c:\Users\Administrator\Downloads\PyQt-Fluent-Widgets-PySide2\examples\gallery\app\view\main_window.py", line 36, in __init__
    super().__init__()
  File "D:\anaconda3\envs\py38\lib\site-packages\qfluentwidgets\window\fluent_window.py", line 150, in __init__
    super().__init__(parent)
  File "D:\anaconda3\envs\py38\lib\site-packages\qfluentwidgets\window\fluent_window.py", line 27, in __init__
    super().__init__(parent=parent)
  File "D:\anaconda3\envs\py38\lib\site-packages\qfluentwidgets\common\animation.py", line 85, in __init__
    self.bgColorObject = BackgroundColorObject(self)
  File "D:\anaconda3\envs\py38\lib\site-packages\qfluentwidgets\common\animation.py", line 171, in __init__
    super().__init__(parent)
TypeError: 'PySide2.QtCore.QObject' called with wrong argument types:
  PySide2.QtCore.QObject(MainWindow)
Supported signatures:
  PySide2.QtCore.QObject(typing.Union[PySide2.QtCore.QObject, NoneType] = None)

Minimum code

# coding:utf-8
import os
import sys

from PySide2.QtCore import Qt, QTranslator
from PySide2.QtGui import QFont
from PySide2.QtWidgets import QApplication
from qfluentwidgets import FluentTranslator

from app.common.config import cfg
from app.view.main_window import MainWindow

# enable dpi scale
if cfg.get(cfg.dpiScale) == "Auto":
    QApplication.setHighDpiScaleFactorRoundingPolicy(
            Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
    QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
else:
    os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "0"
    os.environ["QT_SCALE_FACTOR"] = str(cfg.get(cfg.dpiScale))

QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

# create application
app = QApplication(sys.argv)
app.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings)

# internationalization
locale = cfg.get(cfg.language).value
translator = FluentTranslator(locale)
galleryTranslator = QTranslator()
galleryTranslator.load(locale, "gallery", ".", ":/gallery/i18n")

app.installTranslator(translator)
app.installTranslator(galleryTranslator)

# create main window
w = MainWindow()
w.show()

app.exec_()
zhiyiYo commented 9 months ago

估计你下载错包了,要用 PySide2-Fluent-Widgets

3293406747 commented 9 months ago

我运行了git clone -b PySide2 https://github.com/zhiyiYo/PyQt-Fluent-Widgets.git下载的代码,我又试了次还是报错。

9db44b1896959e20fb905e650997853

zhiyiYo commented 9 months ago

搞个新环境,重新下载包

3293406747 commented 9 months ago

我搞了个新环境可以了,感谢作者。