0
所以我從我的項目中推斷出這個問題,即從主窗口類中注入的Slides Widget類的setCentralWidget導致按鈕的功能(即打開一個新的Widget窗口)主窗口根本不工作。PyQt:setCentralWidget與QPushButton函數衝突
如果我刪除setCentralWidget的按鈕工作正常,所以不妥協的任何功能,我應該用什麼方法呢?我應該使用不同形式的調用Slides Widget類嗎?
任何幫助,將不勝感激,一如既往!謝謝!
from PyQt4 import QtCore, QtGui
import sys
from functools import partial
class MainWindow(QtGui.QMainWindow):
def __init__(self, image_files, parent=None):
super(MainWindow, self).__init__()
self.setupUi(self)
self.slides_widget = Slides(image_files, self)
#If you enable this down below, pushButton will not function
#and instead the slideshow will pop up and function correctly
#self.setCentralWidget(self.slides_widget)
def setupUi(self, MainWindow):
MainWindow.resize(1278, 688)
#MainWindow.setStyleSheet(self.styledata)
self.groupBox = QtGui.QGroupBox(MainWindow)
self.groupBox.setGeometry(QtCore.QRect(490, 220, 120, 371))
self.groupBox.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
self.groupBox.setFlat(False)
self.groupBox.setCheckable(False)
self.pushButton_Desc = QtGui.QPushButton(self.groupBox)
self.pushButton_Desc.setGeometry(QtCore.QRect(20, 30, 71, 61))
self.pushButton_Desc.clicked.connect(partial(self.DescWindow))
self.groupBox.raise_()
self.NewWindow = QtGui.QWidget()
def DescWindow(self):
self.NewWindow.show();
class Slides(QtGui.QWidget):
def __init__(self, image_files, parent=None):
super(Slides, self).__init__(parent)
self.image_files = image_files
self.label = QtGui.QLabel("", self)
self.label.setGeometry(65, 225, 423, 363)
#buttons to rewind and forward
self.button = QtGui.QPushButton(". . .", self)
self.button.setGeometry(200, 100, 140, 30)
self.button.clicked.connect(self.timerEvent)
self.timer = QtCore.QBasicTimer()
self.step = 0
self.delay = 3000 #ms
def timerEvent(self, e=None):
if self.step >= len(self.image_files):
self.timer.start(self.delay, self)
self.step = 0
return
self.timer.start(self.delay, self)
file = self.image_files[self.step]
image = QtGui.QPixmap(file)
self.label.setPixmap(image)
#self.setWindowTitle("{} --> {}".format(str(self.step), file))
self.step += 1
image_files = ["images\slide1.jpg", "images\slide2.jpg", "images\slide3.jpg",
"images\slide4.jpg", "images\slide5.jpg"]
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
Form = MainWindow(image_files)
Form.show()
sys.exit(app.exec_())
我必須找到偷偷摸摸'self.setCentralWidget(self.slides_widget)'只是按鈕下方哈哈我做它的工作!乾杯! 但是我意識到,當我爲我的幻燈片在MainWindow中調用框架時,它將重疊圖像...任何想法如何將框架稱爲圖像的背後? (self.liderwidget.setFrameShadow(QtGui.QFrame.Raised))對我來說並沒有什麼竅門。 – madLad
我建議使用佈局來查找小部件。 – eyllanesc
我想到了在背景色hehehe中使用透明度的問題。謝謝! – madLad