PySide6 Icons not showing once compiled with pyside6-uic
-
I am getting a strange behaviour with Windows app. I have created a test app with a frame and a push button inside that has an icon attached to it with some style applicated to it. When I compile de ui with pyside6-uic and even after changing location of icons channging u"../xxxxxx.ico" to u"./xxxx.ico" and run the app the icons do not apear on the window. But if I compile the ui with pyside2 it works fine and all icons turn up on the window.
It seems simple but I can´t get the reason to fix it.
Any ideas would be grateful.
Regards
-
This is the compiled ui file with pyside6-uic. If I change PySide6 for PySide2 it works.
-- coding: utf-8 --
################################################################################
Form generated from reading UI file 'main_window.ui'
Created by: Qt User Interface Compiler version 6.3.1
WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QFrame, QPushButton, QSizePolicy,
QWidget)class MainWindowForm(object):
def setupUi(self, MainWindowForm):
if not MainWindowForm.objectName():
MainWindowForm.setObjectName(u"MainWindowForm")
MainWindowForm.resize(610, 531)
font = QFont()
font.setBold(True)
MainWindowForm.setFont(font)
MainWindowForm.setStyleSheet(u"border-radius:20px\n"
"")
self.frame = QFrame(MainWindowForm)
self.frame.setObjectName(u"frame")
self.frame.setGeometry(QRect(60, 110, 421, 80))
self.frame.setStyleSheet(u"QFrame{\n"
"background-color: #aeadac\n"
"}")
self.frame.setFrameShape(QFrame.StyledPanel)
self.frame.setFrameShadow(QFrame.Raised)
self.bt_Cancelar = QPushButton(self.frame)
self.bt_Cancelar.setObjectName(u"bt_Cancelar")
self.bt_Cancelar.setGeometry(QRect(290, 30, 121, 28))
font1 = QFont()
font1.setFamilies([u"Segoe UI"])
font1.setPointSize(10)
self.bt_Cancelar.setFont(font1)
self.bt_Cancelar.setStyleSheet(u"QPushButton{\n"
" color: white;\n"
" border-top: 3px transparent;\n"
" border-bottom: 3px transparent;\n"
" border-right: 10px transparent;\n"
" border-left: 10px transparent;\n"
" background-color: #80c342;\n"
"}\n"
"QPushButton::hover {background-color: #ffc13b};\n"
"")
icon = QIcon()
icon.addFile(u"./recursos/iconos/books_library_1768.ico", QSize(), QIcon.Normal, QIcon.Off)
self.bt_Cancelar.setIcon(icon)
self.bt_Cancelar.setIconSize(QSize(25, 25))self.retranslateUi(MainWindowForm) QMetaObject.connectSlotsByName(MainWindowForm) # setupUi def retranslateUi(self, MainWindowForm): MainWindowForm.setWindowTitle(QCoreApplication.translate("MainWindowForm", u"Form", None)) self.bt_Cancelar.setText(QCoreApplication.translate("MainWindowForm", u"Cancelar", None)) # retranslateUi
-
Thanks for the reply, but that was what I thought initially and I corrected it thinking I had solved the problem but it didñ´t.
Why does it work for PySide2 and not for PySide6? There must be something to the new classes ....just an assumption.Anyway I will try using a resource file, and see if it works. Presumably it will I hope. But this simple issue gets me crazy.
Regards,
-
@A-N-E Are you sure the working directory is the same whn running both version ?
You can check working directory with this code:import os print(os.getCwd())
Is the path different in the two files generated?
I'm not sure that's really related to PySide version. If you use an absolute path it will probably work, as well as with resource file. Otherwise you need to fix the relative path of the icon according to the working folder. -
Hi,
No, the same path. I am using the same compiled source file, and just changing libraries PySide6 to PySide2 at the top, it works.
Try it yourself. It´s very annoying when simple issues turn out to "big" problems.
Create with QT Designer v5.11 a form with a simple push button an add an icon and text to it. Compile it with pyside6-uic and mount the window and run it. You will see what I mean.
Many thanks,
-
Good morning, I have created both files one using pyside2-uic and another using pyside2-uic, then just changed libraries on each piece of python files. The only difference is the top part where we import the libraries. PySide2 imports * (all classes) anf PySide6 imports only the widget classes used in the app.
PySide2 app works, shows icons, but PySide6 app doesn´t.
PySide 2
-- coding: utf-8 --
################################################################################
Form generated from reading UI file 'main_window.ui'
Created by: Qt User Interface Compiler version 5.15.2
WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *class MainWindowForm(object):
def setupUi(self, MainWindowForm):
if not MainWindowForm.objectName():
MainWindowForm.setObjectName(u"MainWindowForm")
MainWindowForm.resize(959, 462)
MainWindowForm.setStyleSheet(u"border-radius: 5px")
PySide 6
-- coding: utf-8 --
################################################################################
Form generated from reading UI file 'main_window.ui'
Created by: Qt User Interface Compiler version 6.3.1
WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QFrame, QHBoxLayout, QHeaderView,
QLabel, QLineEdit, QPushButton, QSizePolicy,
QSpacerItem, QTableWidget, QTableWidgetItem, QToolButton,
QVBoxLayout, QWidget)class MainWindowForm(object):
def setupUi(self, MainWindowForm):
if not MainWindowForm.objectName():
MainWindowForm.setObjectName(u"MainWindowForm")
MainWindowForm.resize(959, 462)
MainWindowForm.setStyleSheet(u"border-radius: 5px") -
Hi there again, just to complete my tests. I have tried creating a Resource file instead, and surprisingly, the situation is exactly the same. I have created two resource files using "pyside6-rcc source.qrc > source6.py" and the second, "pyside2-rcc source.qrc > source2.py".
Tests:
1.- Each source file has been imported to its compiled file resulting that the PySide2 works but PySide6 doesn´t.
2.- I have imported the source6 (PySide6 resource file) into PySide2 compiled app and now it doesn´t work, whereas before with resource file source2 (PySide2 compiled) it did. There must be changes on PySide6.QtCore that affect this behaviour.
3.- Now I do the reverse, import source2 (PySide2 compiled) into PySide6 compiled app, resulting that it still doesn´t work.
4.- I have even triedMy Conclusion
PySide6 is not working correctly with icons and images when "ui" is compiled. -
@A-N-E HI Im new. But I had this same issue. The way I corrected this was I made sure to correct the code inside the converted .PY file. Somewhere in the code was my
import resource
. Once I converted my resource file, I made sure that the .PY file knew I made that change as well. Sure enough, it fixed the issue I was having! Hope this helps you!