Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. PySide6 Icons not showing once compiled with pyside6-uic
Forum Updated to NodeBB v4.3 + New Features

PySide6 Icons not showing once compiled with pyside6-uic

Scheduled Pinned Locked Moved Unsolved Qt 6
11 Posts 4 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    A.N.E.
    wrote on last edited by
    #1

    I am getting a strangeQt Designer_Ui_Form.png Form.png 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

    Gojir4G 1 Reply Last reply
    0
    • A A.N.E.

      I am getting a strangeQt Designer_Ui_Form.png Form.png 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

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      @A-N-E Hi, it sounds like a path issue. Don't you see any warning message in the console ?
      To avoid this I would recommend to use The Qt Resource System

      1 Reply Last reply
      0
      • A Offline
        A Offline
        A.N.E.
        wrote on last edited by
        #3

        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
        
        Gojir4G 1 Reply Last reply
        0
        • A Offline
          A Offline
          A.N.E.
          wrote on last edited by
          #4

          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,

          1 Reply Last reply
          0
          • A A.N.E.

            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
            
            Gojir4G Offline
            Gojir4G Offline
            Gojir4
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              A.N.E.
              wrote on last edited by
              #6

              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,

              1 Reply Last reply
              0
              • A Offline
                A Offline
                A.N.E.
                wrote on last edited by
                #7

                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")

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  A.N.E.
                  wrote on last edited by
                  #8

                  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 tried

                  My Conclusion
                  PySide6 is not working correctly with icons and images when "ui" is compiled.

                  JonBJ T 2 Replies Last reply
                  0
                  • A A.N.E.

                    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 tried

                    My Conclusion
                    PySide6 is not working correctly with icons and images when "ui" is compiled.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @A-N-E
                    You may want to report this at https://bugreports.qt.io/.
                    Is Qt 6.4 available to you to try?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      A.N.E.
                      wrote on last edited by
                      #10

                      Thanks, I am not quite sure if v6.4 is released. I will check it out.

                      Also, I will try to report the "supposing" bug.

                      Thanks,

                      1 Reply Last reply
                      0
                      • A A.N.E.

                        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 tried

                        My Conclusion
                        PySide6 is not working correctly with icons and images when "ui" is compiled.

                        T Offline
                        T Offline
                        TheNoodleNator
                        wrote on last edited by
                        #11

                        @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!

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved