0
我正在製作一種圖像查看器,其中我們可以看到加載圖像的直方圖和hsv。代碼按預期運行,除非每次我最大化窗口時,所有QPushButtons都會錯位。如何防止QPushButtons在最大化窗口的同時改變其位置
from PyQt4 import QtGui, QtCore
import cv2
import numpy as np
from matplotlib import pyplot as plt
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
hbox = QtGui.QHBoxLayout(self)
top = QtGui.QFrame(self)
top.setFrameShape(QtGui.QFrame.StyledPanel)
bottomleft = QtGui.QFrame(self)
bottomleft.setFrameShape(QtGui.QFrame.StyledPanel)
bottomright = QtGui.QFrame(self)
bottomright.setFrameShape(QtGui.QFrame.StyledPanel)
splitter1 = QtGui.QSplitter(QtCore.Qt.Vertical)
splitter1.addWidget(top)
splitter2 = QtGui.QSplitter(QtCore.Qt.Horizontal)
splitter2.addWidget(bottomleft)
splitter2.addWidget(bottomright)
splitter1.addWidget(splitter2)
hbox.addWidget(splitter1)
splitter1.setSizes([190,220])
splitter2.setSizes([400,360])
self.setLayout(hbox)
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
self.setGeometry(600, 120, 990, 850)
self.setWindowTitle('PIMAD')
self.setWindowIcon(QtGui.QIcon('imag.jpg'))
self.show()
browseButton = QtGui.QPushButton("Browse")
browseButton.clicked.connect(self.loadFromFile)
browseButton.setToolTip('click to <b>Browse</b>')
histButton = QtGui.QPushButton("")
histButton.setToolTip('For image <b>Histogram</b> click here')
histButton.setIcon(QtGui.QIcon('download.jpg'))
histButton.setIconSize(QtCore.QSize(55,35))
histButton.clicked.connect(self.loadFromHist)
hsvButton = QtGui.QPushButton("")
hsvButton.clicked.connect(self.loadFromHsv)
hsvButton.setToolTip('For <b>Image HSV </b> click here')
hsvButton.setIcon(QtGui.QIcon('hsv.jpg'))
hsvButton.setIconSize(QtCore.QSize(50,35))
self.lbl= QtGui.QLabel()
self.lbl.setScaledContents(True)
bottomleftLayout = QtGui.QHBoxLayout()
self.lbl.setFixedSize(470, 480)
self.lbl2 = QtGui.QLabel()
self.lbl2.setScaledContents(True)
bottomrightLayout = QtGui.QHBoxLayout()
self.lbl3 = QtGui.QLabel()
self.lbl3.setScaledContents(True)
self.lbl3.setFixedSize(300,250)
self.lbl3.move(650,05)
self.lbl3.setParent(top)
self.image = "C:\New folder (2)\logo.jpeg"
self.pix = QtGui.QPixmap(self.image)
self.lbl3.setPixmap(self.pix)
self.lbl3.show()
topLayout = QtGui.QVBoxLayout()
self.fileName = "\Users\Public\Pictures\Sample Pictures\lord.jpg"
self.pixmap = QtGui.QPixmap(self.fileName)
self.lbl.setPixmap(self.pixmap)
bottomleftLayout.addWidget(self.lbl)
bottomleft.setLayout(bottomleftLayout)
bottomrightLayout.addWidget(self.lbl2)
bottomright.setLayout(bottomrightLayout)
topLayout.addWidget(self.lbl3)
topLayout.addStretch(1)
top.setLayout(topLayout)
topLayout.addStretch(1)
browseButton.setParent(top)
histButton.setParent(top)
hsvButton.setParent(top)
browseButton.move(720,260)
histButton.move(790,260)
hsvButton.move(860,260)
browseButton.resize(60,40)
histButton.resize(60,40)
hsvButton.resize(60,40)
browseButton.show()
histButton.show()
hsvButton.show()
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
app.setApplicationName('Example')
main = Example()
main.show()
app.exec_()
其實我必須在右上方顯示兩個徽標 - 左上方和右上方的三個QPushButton,但我只能在左上角放置徽標,無法顯示其他徽標。 – ishani