Bonjour,
Je bloque que un problème qui semble "tout bête"...
J'ai un programme en PyQt4 qui affiche les images d'une webcam avec OpenCV. Tout fonctionne plutôt bien mais.. au moment de changer la résolution :
- de 320x240 vers 640x480, la MainWindow s'agrandit, bien.
- de 640x480 vers 320x240, la MainWindow ne s'ajuste pas à la taille du QLabel, et conserve sa grande taille.
Voici un exemple qui simule ma fenêtre principale:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
 
from PyQt4 import QtCore, QtGui
 
class Ui_MainWindow(QtGui.QMainWindow):
 
    def setupUi(self, MainWindow): 
        self.labelImage = QtGui.QLabel(MainWindow)
        self.labelImage.setGeometry(QtCore.QRect(0, 0, 320, 240))
        self.size1()
        MainWindow.setCentralWidget(self.labelImage)         
        self.action1 = QtGui.QAction(self)
        self.action1.setText("320")
	self.action2 = QtGui.QAction(self)
	self.action2.setText("640")
	self.toolBar = QtGui.QToolBar(MainWindow)
        self.toolBar.addAction(self.action1)
	self.toolBar.addAction(self.action2)
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
	self.connect(self.action1, QtCore.SIGNAL("triggered()"),self.size1)
	self.connect(self.action2, QtCore.SIGNAL("triggered()"),self.size2)
 
    def size1(self):	
	pixmap=QtGui.QPixmap(320,240)
	pixmap.fill()
	self.labelImage.setPixmap(pixmap)
	#self.labelImage.resize(320,240)
	self.adjustSize()
 
    def size2(self):
	self.sh=self.size()
	pixmap=QtGui.QPixmap(640,480)
	pixmap.fill()
	self.labelImage.setPixmap(pixmap)
	#self.labelImage.resize(640,480)
	#self.adjustSize()
 
 
if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
J'ai tenté pas mal d'astuces : resize, adjustSize, sizeHint, minimumSize, maximumSize, utiliser un layout.... mais je n'arrive à rien.
Quelqu'un peut-il m'aider ??
Merci par avance