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]: Getting a bug running any demo.py from the examples folder #702

Closed protik09 closed 9 months ago

protik09 commented 9 months ago

What happened?

Running into a bug running all demo.py in examples folder. I am using either python v3.9.13 or v3.11.7 (I have separate environments set up for both and installed the requirements). For example, if running the following _basicinput > button > demo.py :

# coding:utf-8
import sys

from PySide6.QtCore import Qt, QSize
from PySide6.QtGui import QAction
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QGridLayout
from qfluentwidgets import (Action, Action, DropDownPushButton, DropDownToolButton, PushButton, PrimaryPushButton,
                            HyperlinkButton, setTheme, Theme, ToolButton, ToggleButton, RoundMenu,
                            SplitPushButton, SplitToolButton, PrimaryToolButton, PrimarySplitPushButton,
                            PrimarySplitToolButton, PrimaryDropDownPushButton, PrimaryDropDownToolButton,
                            TogglePushButton, ToggleToolButton, TransparentPushButton, TransparentToolButton,
                            TransparentToggleToolButton, TransparentTogglePushButton, TransparentDropDownToolButton,
                            TransparentDropDownPushButton, PillPushButton, PillToolButton, setCustomStyleSheet,
                            CustomStyleSheet)
from qfluentwidgets import FluentIcon as FIF

class ButtonView(QWidget):

    def __init__(self):
        super().__init__()
        # setTheme(Theme.DARK)
        self.setStyleSheet("ButtonView{background: rgb(255,255,255)}")

class ToolButtonDemo(ButtonView):

    def __init__(self):
        super().__init__()

        self.menu = RoundMenu(parent=self)
        self.menu.addAction(QAction(FIF.SEND_FILL.icon(), 'Send'))
        self.menu.addAction(QAction(FIF.SAVE.icon(), 'Save'))

        # tool button
        self.toolButton = ToolButton(FIF.SETTING, self)

        # !IMPORTANT: add custom style sheet
        # lightQss = 'ToolButton{border-radius: 9px}'
        # darkQss = 'ToolButton{border-radius: 0px; background: red}'
        # setCustomStyleSheet(self.toolButton, lightQss, darkQss)

        # change the size of tool button
        # self.toolButton.resize(50, 50)
        # self.toolButton.setIconSize(QSize(30, 30))

        # drop down tool button
        self.dropDownToolButton = DropDownToolButton(FIF.MAIL, self)
        self.dropDownToolButton.setMenu(self.menu)

        # split tool button
        self.splitToolButton = SplitToolButton(FIF.GITHUB, self)
        self.splitToolButton.setFlyout(self.menu)

        # primary color tool button
        self.primaryToolButton = PrimaryToolButton(FIF.SETTING, self)

        # primary color drop down tool button
        self.primaryDropDownToolButton = PrimaryDropDownToolButton(FIF.MAIL, self)
        self.primaryDropDownToolButton.setMenu(self.menu)

        # primary color split tool button
        self.primarySplitToolButton = PrimarySplitToolButton(FIF.GITHUB, self)
        self.primarySplitToolButton.setFlyout(self.menu)

        # toggle tool button
        self.toggleToolButton = ToggleToolButton(FIF.SETTING, self)
        self.toggleToolButton.toggled.connect(lambda: print('Toggled'))
        self.toggleToolButton.toggle()

        # transparent toggle tool button
        self.transparentToggleToolButton = TransparentToggleToolButton(FIF.GITHUB, self)

        # transparent tool button
        self.tranparentToolButton = TransparentToolButton(FIF.MAIL, self)

        # transparent drop down tool button
        self.transparentDropDownToolButton = TransparentDropDownToolButton(FIF.MAIL, self)
        self.transparentDropDownToolButton.setMenu(self.menu)

        # pill tool button
        self.pillToolButton1 = PillToolButton(FIF.CALENDAR, self)
        self.pillToolButton2 = PillToolButton(FIF.CALENDAR, self)
        self.pillToolButton3 = PillToolButton(FIF.CALENDAR, self)
        self.pillToolButton2.setDisabled(True)
        self.pillToolButton3.setChecked(True)
        self.pillToolButton3.setDisabled(True)

        # add buttons to layout
        self.gridLayout = QGridLayout(self)
        self.gridLayout.addWidget(self.toolButton, 0, 0)
        self.gridLayout.addWidget(self.dropDownToolButton, 0, 1)
        self.gridLayout.addWidget(self.splitToolButton, 0, 2)
        self.gridLayout.addWidget(self.primaryToolButton, 1, 0)
        self.gridLayout.addWidget(self.primaryDropDownToolButton, 1, 1)
        self.gridLayout.addWidget(self.primarySplitToolButton, 1, 2)
        self.gridLayout.addWidget(self.toggleToolButton, 2, 0)
        self.gridLayout.addWidget(self.transparentToggleToolButton, 2, 1)
        self.gridLayout.addWidget(self.tranparentToolButton, 3, 0)
        self.gridLayout.addWidget(self.transparentDropDownToolButton, 3, 1)
        self.gridLayout.addWidget(self.pillToolButton1, 4, 0)
        self.gridLayout.addWidget(self.pillToolButton2, 4, 1)
        self.gridLayout.addWidget(self.pillToolButton3, 4, 2)

        self.resize(300, 300)

class PushButtonDemo(ButtonView):

    def __init__(self):
        super().__init__()

        self.menu = RoundMenu(parent=self)
        self.menu.addAction(Action(FIF.BASKETBALL, 'Basketball'))
        self.menu.addAction(Action(FIF.ALBUM, 'Sing'))
        self.menu.addAction(Action(FIF.MUSIC, 'Music'))

        # push button
        self.pushButton1 = PushButton('Standard push button')
        self.pushButton2 = PushButton(FIF.FOLDER, 'Standard push button with icon', self)

        # primary color push button
        self.primaryButton1 = PrimaryPushButton('Accent style button', self)
        self.primaryButton2 = PrimaryPushButton(FIF.UPDATE, 'Accent style button with icon', self)

        # transparent push button
        self.transparentPushButton1 = TransparentPushButton('Transparent push button', self)
        self.transparentPushButton2 = TransparentPushButton(FIF.BOOK_SHELF, 'Transparent push button', self)

        # toggle button
        self.toggleButton1 = TogglePushButton('Toggle push button', self)
        self.toggleButton2 = TogglePushButton(FIF.SEND, 'Toggle push button', self)

        # transparent toggle push button
        self.transparentTogglePushButton1 = TransparentTogglePushButton('Transparent toggle button', self)
        self.transparentTogglePushButton2 = TransparentTogglePushButton(FIF.BOOK_SHELF, 'Transparent toggle button', self)

        # drop down push button
        self.dropDownPushButton1 = DropDownPushButton('Email', self)
        self.dropDownPushButton2 = DropDownPushButton(FIF.MAIL, 'Email', self)
        self.dropDownPushButton1.setMenu(self.menu)
        self.dropDownPushButton2.setMenu(self.menu)

        # primary color drop down push button
        self.primaryDropDownPushButton1 = PrimaryDropDownPushButton('Email', self)
        self.primaryDropDownPushButton2 = PrimaryDropDownPushButton(FIF.MAIL, 'Email', self)
        self.primaryDropDownPushButton1.setMenu(self.menu)
        self.primaryDropDownPushButton2.setMenu(self.menu)

        # primary color drop down push button
        self.transparentDropDownPushButton1 = TransparentDropDownPushButton('Email', self)
        self.transparentDropDownPushButton2 = TransparentDropDownPushButton(FIF.MAIL, 'Email', self)
        self.transparentDropDownPushButton1.setMenu(self.menu)
        self.transparentDropDownPushButton2.setMenu(self.menu)

        # split push button
        self.splitPushButton1 = SplitPushButton('Split push button', self)
        self.splitPushButton2 = SplitPushButton(FIF.GITHUB, 'Split push button', self)
        self.splitPushButton1.setFlyout(self.menu)
        self.splitPushButton2.setFlyout(self.menu)

        # primary split push button
        self.primarySplitPushButton1 = PrimarySplitPushButton('Split push button', self)
        self.primarySplitPushButton2 = PrimarySplitPushButton(FIF.GITHUB, 'Split push button', self)
        self.primarySplitPushButton1.setFlyout(self.menu)
        self.primarySplitPushButton2.setFlyout(self.menu)

        # hyperlink button
        self.hyperlinkButton1 = HyperlinkButton(
            url='https://github.com/zhiyiYo/QMaterialWidgets',
            text='Hyper link button',
            parent=self
        )
        self.hyperlinkButton2 = HyperlinkButton(
            url='https://github.com/zhiyiYo/QMaterialWidgets',
            text='Hyper link button',
            parent=self,
            icon=FIF.LINK
        )

        # pill push button
        self.pillPushButton1 = PillPushButton('Pill Push Button', self)
        self.pillPushButton2 = PillPushButton(FIF.CALENDAR, 'Pill Push Button', self)

        self.gridLayout = QGridLayout(self)
        self.gridLayout.addWidget(self.pushButton1, 0, 0)
        self.gridLayout.addWidget(self.pushButton2, 0, 1)
        self.gridLayout.addWidget(self.primaryButton1, 1, 0)
        self.gridLayout.addWidget(self.primaryButton2, 1, 1)
        self.gridLayout.addWidget(self.transparentPushButton1, 2, 0)
        self.gridLayout.addWidget(self.transparentPushButton2, 2, 1)

        self.gridLayout.addWidget(self.toggleButton1, 3, 0)
        self.gridLayout.addWidget(self.toggleButton2, 3, 1)
        self.gridLayout.addWidget(self.transparentTogglePushButton1, 4, 0)
        self.gridLayout.addWidget(self.transparentTogglePushButton2, 4, 1)

        self.gridLayout.addWidget(self.splitPushButton1, 5, 0)
        self.gridLayout.addWidget(self.splitPushButton2, 5, 1)
        self.gridLayout.addWidget(self.primarySplitPushButton1, 6, 0)
        self.gridLayout.addWidget(self.primarySplitPushButton2, 6, 1)

        self.gridLayout.addWidget(self.dropDownPushButton1, 7, 0, Qt.AlignLeft)
        self.gridLayout.addWidget(self.dropDownPushButton2, 7, 1, Qt.AlignLeft)
        self.gridLayout.addWidget(self.primaryDropDownPushButton1, 8, 0, Qt.AlignLeft)
        self.gridLayout.addWidget(self.primaryDropDownPushButton2, 8, 1, Qt.AlignLeft)
        self.gridLayout.addWidget(self.transparentDropDownPushButton1, 9, 0, Qt.AlignLeft)
        self.gridLayout.addWidget(self.transparentDropDownPushButton2, 9, 1, Qt.AlignLeft)

        self.gridLayout.addWidget(self.pillPushButton1, 10, 0, Qt.AlignLeft)
        self.gridLayout.addWidget(self.pillPushButton2, 10, 1, Qt.AlignLeft)

        self.gridLayout.addWidget(self.hyperlinkButton1, 11, 0, Qt.AlignLeft)
        self.gridLayout.addWidget(self.hyperlinkButton2, 11, 1, Qt.AlignLeft)

        self.resize(600, 700)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    w1 = ToolButtonDemo()
    w1.show()

    w2 = PushButtonDemo()
    w2.show()
    app.exec()

It gives the following error:

Traceback (most recent call last):
  File "~\PyQt-Fluent-Widgets-examples\basic_input\button\demo.py", line 223, in <module>
    w1 = ToolButtonDemo()
         ^^^^^^^^^^^^^^^^
  File "~\PyQt-Fluent-Widgets-examples\basic_input\button\demo.py", line 32, in __init__
    self.menu = RoundMenu(parent=self)
                ^^^^^^^^^^^^^^^^^^^^^^
  File "~\AppData\Roaming\Python\Python311\site-packages\qfluentwidgets\components\widgets\menu.py", line 266, in __init__
    super().__init__(parent=parent)
TypeError: arguments did not match any overloaded call:
  QMenu(parent: Optional[QWidget] = None): argument 'parent' has unexpected type 'ToolButtonDemo'
  QMenu(title: Optional[str], parent: Optional[QWidget] = None): not enough arguments

Operation System

Windows11 23H2

Python Version

3.9.13 & 3.11.7

PyQt/PySide Version

PySide6

PyQt/PySide-Fluent-Widgets Version

PyQt5/PySide-Fluent-Widgets v1.4.1

How to Reproduce?

Run ANY demo.py programs from the examples folder in any Powershell window in Windows 11 with Python 3.9.13 or 3.11.7, with PySide6 installed.

Note: When installing PySide-Fluent-Widgets from pip it installs PyQt5 as part of its requirements.

Minimum code

# Run any demo.py from examples folder
zhiyiYo commented 9 months ago

you should install PySide6-Fluent-Widgets

protik09 commented 9 months ago

@zhiyiYo I installed your library from the Readme.md using

pip install PyQt-Fluent-Widgets -i https://pypi.org/simple/

Is there another method? Or do I need to build the wheel myself from the PySide6 branch on Github and NOT install from pip?

zhiyiYo commented 9 months ago

switch to pyside6 branch, and follow the steps in readme

protik09 commented 9 months ago

@zhiyiYo Thank you very much for your help. I appreciate it. :)