簡體   English   中英

對象沒有屬性 PyQt5 | 刪除最大化按鈕

[英]Object has no attribute PyQt5 | Removing Maximize Button

我正在嘗試刪除程序主窗口中的最大化按鈕,問題是我收到一個錯誤消息:

'main_window_logic' 對象沒有屬性 'Main_Window'

我可以引用主窗口中的任何對象,我只是不能引用主窗口本身我使用Qt Designer創建窗口。

對此有什么解釋嗎? 這是由使用uic.loadUiType()引起的嗎?

Python(PyQt5)代碼:

from PyQt5 import QtCore, QtGui, QtWidgets, uic
import sys

baseUIClass, baseUIWidget = uic.loadUiType("main_window.ui")

class main_window_logic(baseUIWidget, baseUIClass):
    """ Handles Logic for the Main Window (main_window.ui)"""
    def __init__(self, parent = None):
        super(main_window_logic,self).__init__(parent)
        self.setupUi(self)
        self.listWidget.setAlternatingRowColors(True)
        self.Main_Window.setWindowFlags(QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint)
   

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    ui = main_window_logic(None)
    ui.show()
    sys.exit(app.exec_())

XML 代碼:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Main_Window</class>
 <widget class="QMainWindow" name="Main_Window">
  <property name="enabled">
   <bool>true</bool>
  </property>
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>930</width>
    <height>715</height>
   </rect>
  </property>
  <property name="maximumSize">
   <size>
    <width>930</width>
    <height>715</height>
   </size>
  </property>
  <property name="sizeIncrement">
   <size>
    <width>0</width>
    <height>4</height>
   </size>
  </property>
  <property name="baseSize">
   <size>
    <width>4</width>
    <height>0</height>
   </size>
  </property>
  <property name="cursor">
   <cursorShape>ArrowCursor</cursorShape>
  </property>
  <property name="windowTitle">
   <string>title</string>
  </property>
  <property name="windowOpacity">
   <double>4.000000000000000</double>
  </property>
  <property name="styleSheet">
   <string notr="true">QMainWindow {
background-color: qlineargradient(spread:pad, x1:0.0100548, y1:0.631, x2:0.229627, y2:0.931, stop:0.440607 rgba(97, 35, 86, 255), stop:1 rgba(105, 25, 98, 255));

}

    </string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QFrame" name="frame">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>20</y>
      <width>251</width>
      <height>661</height>
     </rect>
    </property>
    <property name="baseSize">
     <size>
      <width>0</width>
      <height>0</height>
     </size>
    </property>
    <property name="styleSheet">
     <string notr="true">QFrame {

    background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(87, 54, 185, 255), stop:1 rgba(168, 41, 41, 255));

}   </string>
    </property>
    <property name="frameShape">
     <enum>QFrame::StyledPanel</enum>
    </property>
    <property name="frameShadow">
     <enum>QFrame::Raised</enum>
    </property>
    <widget class="QListWidget" name="listWidget">
     <property name="geometry">
      <rect>
       <x>0</x>
       <y>0</y>
       <width>251</width>
       <height>661</height>
      </rect>
     </property>
     <property name="baseSize">
      <size>
       <width>0</width>
       <height>0</height>
      </size>
     </property>
     <property name="styleSheet">
      <string notr="true">QListWidget{
    

font: 75 11pt &quot;Ubuntu Mono&quot;;

    background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(87, 54, 185, 255), stop:1 rgba(168, 41, 41, 255));
;
    alternate-background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(226, 24, 24, 255), stop:0.985377 rgba(207, 112, 0, 255));
    


}


</string>
     </property>
     <property name="itemAlignment">
      <set>Qt::AlignCenter</set>
     </property>
    </widget>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>930</width>
     <height>22</height>
    </rect>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

謝謝

Main_Window 是頂層,即窗口,在您的情況下是通過self訪問的:

self.setWindowFlags(
    QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM