Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QPalette' object has no attribute 'set_color' #86

Open
YeongbinLim opened this issue Feb 14, 2023 · 1 comment
Open

QPalette' object has no attribute 'set_color' #86

YeongbinLim opened this issue Feb 14, 2023 · 1 comment

Comments

@YeongbinLim
Copy link

YeongbinLim commented Feb 14, 2023

`import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
from qt_material import apply_stylesheet
from qt_material import list_themes
def MyApp():
app = QApplication(sys.argv)
widget = QWidget()

textLabel = QLabel(widget)
textLabel.setText("Hello World!")
textLabel.move(150, 200)

widget.setGeometry(50, 50, 400, 400)
widget.setWindowTitle("PyQt5 Example")
list_themes()
apply_stylesheet(app, theme='dark_teal.xml')

widget.show()
sys.exit(app.exec_())

if name == 'main':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())`

AttributeError: type object 'ColorRole' has no attribute 'Text'

During handling of the above exception, another exception occurred:

File "D:\study\pyqt\test.py", line 18, in MyApp
apply_stylesheet(app, theme='dark_teal.xml')
File "D:\study\pyqt\test.py", line 25, in
ex = MyApp()
AttributeError: 'QPalette' object has no attribute 'set_color'

version is
qt-material 2.14
PyQt5 5.15.1

in init.py file
I see u define pyqt5 as this code
"
try:
print(dir(QPalette))
if hasattr(
QPalette, 'PlaceholderText'
): # pyqt5, pyside2, pyside6
default_palette.setColor(QPalette.PlaceholderText, color)
else: # pyqt6
default_palette.setColor(QPalette.ColorRole.Text, color)
QGuiApplication.setPalette(default_palette)
"

but there is no PlaceholderText in PyQt5/QtGui.pyi
So we need to distinguish PyQt5 another way

@YeongbinLim
Copy link
Author

image
making it annotation worked with me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant