Почему мои значки не отображаются в главном окне моего проекта PySide2? - PullRequest
0 голосов
/ 26 марта 2020

У меня есть базовый c проект Pyside2 со следующим кодом main.py:

import sys
import resources_rc
from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import QApplication

class MyApp():
    def __init__(self):
        super().__init__()
        self.ui = QUiLoader().load("MyApp.ui")
        self.ui.show()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    ui = MyApp()
    app.exec_()

Моя структура папок выглядит следующим образом:

.
├── main.py
├── MyApp.ui
├── Resources.qrc
├── resources_rc.py
└── icons
    ├── pqClip.png
    ├── pqSlice.png
    ├── pqThreshold.png
    ├── pqXplus.png
    ├── pqXminus.png
    ├── pqYplus.png
    ├── pqYminus.png
    ├── pqZplus.png
    ├── pqZminus.png

My Resources.qr * Файл 1023 * выглядит следующим образом:

<RCC>
  <qresource>
    <file>icons/pqClip.png</file>
    <file>icons/pqSlice.png</file>
    <file>icons/pqThreshold.png</file>
    <file>icons/pqXplus.png</file>
    <file>icons/pqXminus.png</file>
    <file>icons/pqYplus.png</file>
    <file>icons/pqYminus.png</file>
    <file>icons/pqZplus.png</file>
    <file>icons/pqZminus.png</file>
  </qresource>
</RCC>

MyApp.ui:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>1217</width>
    <height>729</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MyApp</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QGridLayout" name="gridLayout">
    <property name="leftMargin">
     <number>0</number>
    </property>
    <property name="topMargin">
     <number>0</number>
    </property>
    <property name="rightMargin">
     <number>0</number>
    </property>
    <property name="bottomMargin">
     <number>0</number>
    </property>
    <property name="horizontalSpacing">
     <number>4</number>
    </property>
    <item row="0" column="0">
     <widget class="QSplitter" name="splitter">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
      <widget class="QFrame" name="frame_2">
       <property name="frameShape">
        <enum>QFrame::StyledPanel</enum>
       </property>
       <property name="frameShadow">
        <enum>QFrame::Raised</enum>
       </property>
       <layout class="QGridLayout" name="gridLayout_2">
        <property name="leftMargin">
         <number>0</number>
        </property>
        <property name="topMargin">
         <number>0</number>
        </property>
        <property name="rightMargin">
         <number>0</number>
        </property>
        <property name="bottomMargin">
         <number>0</number>
        </property>
        <property name="verticalSpacing">
         <number>2</number>
        </property>
        <item row="0" column="0">
         <widget class="QWidget" name="menuWidget" native="true">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
            <horstretch>0</horstretch>
            <verstretch>0</verstretch>
           </sizepolicy>
          </property>
          <layout class="QHBoxLayout" name="menuLayout">
           <property name="spacing">
            <number>4</number>
           </property>
           <property name="leftMargin">
            <number>0</number>
           </property>
           <property name="topMargin">
            <number>0</number>
           </property>
           <property name="rightMargin">
            <number>0</number>
           </property>
           <property name="bottomMargin">
            <number>0</number>
           </property>
           <item>
            <widget class="QWidget" name="filterBtnWidget" native="true">
             <property name="sizePolicy">
              <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
             </property>
             <layout class="QHBoxLayout" name="filterBtnLayout">
              <property name="spacing">
               <number>4</number>
              </property>
              <property name="leftMargin">
               <number>0</number>
              </property>
              <property name="topMargin">
               <number>0</number>
              </property>
              <property name="rightMargin">
               <number>0</number>
              </property>
              <property name="bottomMargin">
               <number>0</number>
              </property>
              <item>
               <widget class="QPushButton" name="clipBtn">
                <property name="toolTip">
                 <string>Add Clip Filter</string>
                </property>
                <property name="statusTip">
                 <string/>
                </property>
                <property name="text">
                 <string/>
                </property>
                <property name="icon">
                 <iconset resource="../Workspace/MyApp/Resources.qrc">
                  <normaloff>:/icons/pqClip.png</normaloff>:/icons/pqClip.png</iconset>
                </property>
                <property name="iconSize">
                 <size>
                  <width>24</width>
                  <height>24</height>
                 </size>
                </property>
                <property name="flat">
                 <bool>true</bool>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QPushButton" name="sliceBtn">
                <property name="toolTip">
                 <string>Add Slice Filter</string>
                </property>
                <property name="statusTip">
                 <string/>
                </property>
                <property name="text">
                 <string/>
                </property>
                <property name="icon">
                 <iconset resource="../Workspace/MyApp/Resources.qrc">
                  <normaloff>:/icons/pqSlice.png</normaloff>:/icons/pqSlice.png</iconset>
                </property>
                <property name="iconSize">
                 <size>
                  <width>24</width>
                  <height>24</height>
                 </size>
                </property>
                <property name="flat">
                 <bool>true</bool>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QPushButton" name="thresholdBtn">
                <property name="toolTip">
                 <string>Add Threshold Filter</string>
                </property>
                <property name="statusTip">
                 <string/>
                </property>
                <property name="text">
                 <string/>
                </property>
                <property name="icon">
                 <iconset resource="../Workspace/MyApp/Resources.qrc">
                  <normaloff>:/icons/pqThreshold.png</normaloff>:/icons/pqThreshold.png</iconset>
                </property>
                <property name="iconSize">
                 <size>
                  <width>24</width>
                  <height>24</height>
                 </size>
                </property>
                <property name="flat">
                 <bool>true</bool>
                </property>
               </widget>
              </item>
             </layout>
            </widget>
           </item>
           <item>
            <spacer name="horizontalSpacer">
             <property name="orientation">
              <enum>Qt::Horizontal</enum>
             </property>
             <property name="sizeHint" stdset="0">
              <size>
               <width>1</width>
               <height>20</height>
              </size>
             </property>
            </spacer>
           </item>
           <item>
            <widget class="QWidget" name="cameraAxisWidget" native="true">
             <property name="sizePolicy">
              <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
             </property>
             <layout class="QHBoxLayout" name="cameraAxisLayout">
              <property name="spacing">
               <number>4</number>
              </property>
              <property name="leftMargin">
               <number>0</number>
              </property>
              <property name="topMargin">
               <number>0</number>
              </property>
              <property name="rightMargin">
               <number>0</number>
              </property>
              <property name="bottomMargin">
               <number>0</number>
              </property>
              <item>
               <widget class="QPushButton" name="cameraXpBtn">
                <property name="toolTip">
                 <string extracomment="X+">Set view direction to +X</string>
                </property>
                <property name="statusTip">
                 <string>Set view direction to +X</string>
                </property>
                <property name="text">
                 <string/>
                </property>
                <property name="icon">
                 <iconset resource="../Workspace/MyApp/Resources.qrc">
                  <normaloff>:/icons/pqXplus.png</normaloff>:/icons/pqXplus.png</iconset>
                </property>
                <property name="iconSize">
                 <size>
                  <width>24</width>
                  <height>24</height>
                 </size>
                </property>
                <property name="flat">
                 <bool>true</bool>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QPushButton" name="cameraXmBtn">
                <property name="toolTip">
                 <string extracomment="X-">Set view direction to -X</string>
                </property>
                <property name="statusTip">
                 <string>Set view direction to -X</string>
                </property>
                <property name="text">
                 <string/>
                </property>
                <property name="icon">
                 <iconset resource="../Workspace/MyApp/Resources.qrc">
                  <normaloff>:/icons/pqXminus.png</normaloff>:/icons/pqXminus.png</iconset>
                </property>
                <property name="iconSize">
                 <size>
                  <width>24</width>
                  <height>24</height>
                 </size>
                </property>
                <property name="flat">
                 <bool>true</bool>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QPushButton" name="cameraYpBtn">
                <property name="toolTip">
                 <string extracomment="Y+">Set view direction to +Y</string>
                </property>
                <property name="statusTip">
                 <string>Set view direction to +Y</string>
                </property>
                <property name="text">
                 <string/>
                </property>
                <property name="icon">
                 <iconset resource="../Workspace/MyApp/Resources.qrc">
                  <normaloff>:/icons/pqYplus.png</normaloff>:/icons/pqYplus.png</iconset>
                </property>
                <property name="iconSize">
                 <size>
                  <width>24</width>
                  <height>24</height>
                 </size>
                </property>
                <property name="flat">
                 <bool>true</bool>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QPushButton" name="cameraYmBtn">
                <property name="toolTip">
                 <string extracomment="Y-">Set view direction to -Y</string>
                </property>
                <property name="statusTip">
                 <string>Set view direction to -Y</string>
                </property>
                <property name="text">
                 <string/>
                </property>
                <property name="icon">
                 <iconset resource="../Workspace/MyApp/Resources.qrc">
                  <normaloff>:/icons/pqYminus.png</normaloff>:/icons/pqYminus.png</iconset>
                </property>
                <property name="iconSize">
                 <size>
                  <width>24</width>
                  <height>24</height>
                 </size>
                </property>
                <property name="flat">
                 <bool>true</bool>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QPushButton" name="cameraZpBtn">
                <property name="toolTip">
                 <string extracomment="Z+">Set view direction to +Z</string>
                </property>
                <property name="statusTip">
                 <string>Set view direction to +Z</string>
                </property>
                <property name="text">
                 <string/>
                </property>
                <property name="icon">
                 <iconset resource="../Workspace/MyApp/Resources.qrc">
                  <normaloff>:/icons/pqZplus.png</normaloff>:/icons/pqZplus.png</iconset>
                </property>
                <property name="iconSize">
                 <size>
                  <width>24</width>
                  <height>24</height>
                 </size>
                </property>
                <property name="flat">
                 <bool>true</bool>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QPushButton" name="cameraZmBtn">
                <property name="toolTip">
                 <string extracomment="Z-">Set view direction to -Z</string>
                </property>
                <property name="statusTip">
                 <string>Set view direction to -Z</string>
                </property>
                <property name="text">
                 <string/>
                </property>
                <property name="icon">
                 <iconset resource="../Workspace/MyApp/Resources.qrc">
                  <normaloff>:/icons/pqZminus.png</normaloff>:/icons/pqZminus.png</iconset>
                </property>
                <property name="iconSize">
                 <size>
                  <width>24</width>
                  <height>24</height>
                 </size>
                </property>
                <property name="flat">
                 <bool>true</bool>
                </property>
               </widget>
              </item>
             </layout>
            </widget>
           </item>
          </layout>
         </widget>
        </item>
       </layout>
      </widget>
     </widget>
    </item>
   </layout>
  </widget>
  <action name="actionRegistration">
   <property name="text">
    <string>Registration</string>
   </property>
  </action>
  <action name="actionI_O">
   <property name="text">
    <string>I/O</string>
   </property>
  </action>
  <action name="actionFusion">
   <property name="text">
    <string>Fusion</string>
   </property>
  </action>
  <action name="actionCustom">
   <property name="text">
    <string>Custom</string>
   </property>
  </action>
 </widget>
 <resources>
  <include location="../Workspace/MyApp/Resources.qrc"/>
 </resources>
 <connections/>
</ui>

Я установил значки из файла Resources.qr c на различные кнопки в моем пользовательском интерфейсе, используя Qt Designer.

Я выполнил эту команду для создания моего файла resources_r c .py: pyside2-rcc -o resources_rc.py Resources.qrc.

Когда я запускаю python main.py, чтобы выполнить мое приложение, ни один из моих значков из мой QR C файл появляется в пользовательском интерфейсе.

Что-то еще, что я должен сделать, чтобы заставить это работать? Спасибо.

...