<p>这是一个更干净的、更具类化(pythonicpyqt)版本的程序,我把注释掉的东西放在里面,让你看看它应该在哪里,但是我删除了你的坐标系,用创建GUI的更标准的布局样式替换了它。在</p>
<p>我在win10上用python3.7pyqt5测试了这个问题,所以如果有操作系统的问题,你会知道的,但是我的猜测是,在某些地方出现了一个断开连接的问题,而这正是您遇到的问题。在</p>
<p>同样,你的按钮设计永远不会创建一个空白行,因为它总是把一些东西放在一行,我只需点击按钮而不输入任何东西</p>
<pre><code>from sys import exit as sysExit
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont, QCursor
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QHBoxLayout, QVBoxLayout, QDockWidget, QStyleFactory
from PyQt5.QtWidgets import QPushButton, QLineEdit, QLabel, QSlider, QTextBrowser, QMenuBar, QStatusBar
class MenuToolBar(QDockWidget):
def __init__(self, MainWin):
QDockWidget.__init__(self)
self.MainWin = MainWin
self.MainMenu = MainWin.menuBar()
# ******* Create the Help Menu *******
self.HelpMenu = self.MainMenu.addMenu('Help')
class CenterPanel(QWidget):
def __init__(self, parent):
QWidget.__init__(self)
# General Font Object for a couple of Buttons
btnFont = QFont()
btnFont.setFamily('Arial')
btnFont.setItalic(True)
# First Item Horizontal Box 1 Containing the AddLib Entry and Button
self.lnAdlibEntry = QLineEdit(self)
# self.lnAdlibEntry.setGeometry(QRect(30, 20, 501, 51))
# self.lnAdlibEntry.resize(501, 51)
self.btnAddLine = QPushButton(self)
# Left, Top, Width, Height
# self.btnAddLine.setGeometry(QRect(530, 0, 91, 51))
# Width, Height
# self.btnAddLine.resize(91, 51)
self.btnAddLine.setFont(btnFont)
self.btnAddLine.setCursor(QCursor(Qt.PointingHandCursor))
self.btnAddLine.setText('Adlib')
self.btnAddLine.clicked.connect(parent.AddLineAdlib)
HBox1 = QHBoxLayout()
HBox1.addWidget(self.lnAdlibEntry)
HBox1.addWidget(self.btnAddLine)
# Second Item Vertical Box 1 Containing the AdlibEntry LineEdit and RTD Label and RTD Slider
self.lblDial = QLabel(self)
# self.lblDial.setGeometry(QRect(640, 20, 71, 16))
# self.lblDial.resize(71, 16)
self.lblDial.setText("RTD Level")
self.sldrRtd = QSlider(self)
# self.sldrRtd.setGeometry(QRect(620, 40, 101, 22))
# self.sldrRtd.resize(101, 22)
self.sldrRtd.setOrientation(Qt.Horizontal)
VBox1 = QVBoxLayout()
VBox1.addWidget(self.lblDial)
VBox1.addWidget(self.sldrRtd)
# Third Item Horizontal Box 2 containing the Save, No Adlib and Delete buttons
self.btnNoAdlib = QPushButton(self)
# self.btnNoAdlib.setGeometry(QRect(530, 50, 91, 51))
# self.btnNoAdlib.resize(91, 51)
self.btnNoAdlib.setFont(btnFont)
self.btnNoAdlib.setCursor(QCursor(Qt.PointingHandCursor))
self.btnNoAdlib.setText("No Adlib")
self.btnSave = QPushButton(self)
# self.btnSave.setGeometry(QRect(30, 80, 91, 32))
# self.btnSave.resize(91, 32)
self.btnSave.setCursor(QCursor(Qt.PointingHandCursor))
self.btnSave.setText('Save')
self.btnDelete = QPushButton(self)
# self.btnDelete.setGeometry(QRect(120, 80, 91, 32))
# self.btnDelete.resize(91, 32)
self.btnDelete.setCursor(QCursor(Qt.PointingHandCursor))
self.btnDelete.setText('Delete')
HBox2 = QHBoxLayout()
HBox2.addWidget(self.btnSave)
HBox2.addStretch(1)
HBox2.addWidget(self.btnNoAdlib)
HBox2.addStretch(1)
HBox2.addWidget(self.btnDelete)
# Sixth Item Text Browser
self.txtBrowser = QTextBrowser(self)
# self.txtBrowser.setGeometry(QRect(20, 120, 701, 501))
# self.txtBrowser.resize(701, 501)
VBox2 = QVBoxLayout()
VBox2.addLayout(HBox1)
VBox2.addLayout(VBox1)
VBox2.addLayout(HBox2)
VBox2.addWidget(self.txtBrowser)
self.setLayout(VBox2)
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.Lyrics = ''
self.Adlib = ' (Placeholder adlib)'
self.setWindowTitle('Main Window')
self.resize(742, 680)
self.CenterPane = CenterPanel(self)
self.setCentralWidget(self.CenterPane)
self.MenuBar = MenuToolBar(self)
# self.MenuBar.setGeometry(QRect(0, 0, 742, 22))
self.SetStatusBar(self)
self.setStyle(QStyleFactory.create('Cleanlooks'))
def SetStatusBar(self, parent):
StatusMsg = ''
parent.StatBar = parent.statusBar()
if len(StatusMsg) < 1:
StatusMsg = 'Ready'
parent.StatBar.showMessage(StatusMsg)
def AddLineAdlib(self):
# This statement retains everything previously in Lyrics and
# everything in the AdlibEntry box and everything in Adlib which
# I am not sure is what you are wanting but it is what you had
self.Lyrics += self.CenterPane.lnAdlibEntry.text() + self.Adlib + '\n'
self.CenterPane.lnAdlibEntry.clear()
self.CenterPane.txtBrowser.setText(self.Lyrics)
def AddLineNoAdlib(self):
pass
def Save(self):
pass
def DeleteLine(self):
pass
if __name__ == "__main__":
MainThred = QApplication([])
MainGUI = MainWindow()
MainGUI.show()
sysExit(MainThred.exec_())
</code></pre>
<p>编辑:我有一个奇怪的箭头出现在我的屏幕上,它似乎QStyleFactory调用删除了,我调整了StatusBar声明,使其更模块化,以防以后您想类化它</p>