[PyQt] image with scrollbars in a qlabel how ?

Joachim Schmitz js at aixtraware.de
Mon Nov 12 21:22:36 GMT 2007


Hi,

i want to show a dialog where one can enter a text based on an image shown.
The code below does that, except for the fact, that the image always has 
the same size, and that no scrollbars apear, what I am doing wrong ?
I actually want the imageLabel look like the centralWidget in the 
imageviewer example ?




class RenameWidget(QtGui.QDialog): ###(
     def __init__(self, image_path, parent=None):
         QtGui.QDialog.__init__(self, parent)
         self.setWindowTitle(self.tr('Filename: %s' % image_path))
         project = getProject()
         self.proben_key = proben_key = 
os.path.splitext(os.path.split(image_path)[1])[0].upper()
         self.probe = project.proben.get(proben_key,None)
         if self.probe is None:
             self.probe = Probe(proben_key)
             project.proben[proben_key] = self.probe
             dumpToProject(project)
         probenNameLabel = QtGui.QLabel(self.tr("Proben Bezeichnung:"))
         self.probenNameEdit = QtGui.QLineEdit(self.probe.bezeichnung)
         self.connect(self.probenNameEdit,
                      QtCore.SIGNAL("editingFinished()"), 
self.setProbenName)
         self.connect(self.probenNameEdit, 
QtCore.SIGNAL("returnPressed()"), self.setProbenName)
         self.connect(self.probenNameEdit, 
QtCore.SIGNAL("textChanged()"), self.setProbenName)
         self.connect(self.probenNameEdit, 
QtCore.SIGNAL("textEdited()"), self.setProbenName)
         okButton = QtGui.QPushButton(self.tr("Save + Exit"))
         self.connect(okButton, QtCore.SIGNAL("clicked()"), self, 
QtCore.SLOT("accept()"))
         cancelButton = QtGui.QPushButton(self.tr("Cancel"))
         self.connect(cancelButton, QtCore.SIGNAL("clicked()"), self, 
QtCore.SLOT("reject()"))

         image = QImage()
         image.load(image_path)
        self.imageLabel = QtGui.QLabel()
         self.imageLabel.setBackgroundRole(QtGui.QPalette.Base)
         self.imageLabel.setSizePolicy(QtGui.QSizePolicy.Ignored, 
QtGui.QSizePolicy.Ignored)
         self.imageLabel.setScaledContents(True)

         #self.setCentralWidget(self.scrollArea)
         self.imageLabel.setMinimumSize(project.pr_px.size())
         self.imageLabel.setBaseSize(project.pr_px.size())
         scrollArea = QtGui.QScrollArea()
         scrollArea.setBackgroundRole(QtGui.QPalette.Dark)
         scrollArea.setWidget(self.imageLabel)
         #self.setCentralWidget(self.imageLabel)
         #self.imageLabel.scrollArea.setWidget(self.imageLabel)
         #self.imageLabel.setMaximumSize(100,100)
         self.imageLabel.resize(100,100)
 
self.imageLabel.setPixmap(QtGui.QPixmap.fromImage(image.copy(project.pr_px)))
         #self.imageLabel.adjustSize()
         lineLayout = QtGui.QHBoxLayout()
         lineLayout.addWidget(probenNameLabel)
         lineLayout.addWidget(self.probenNameEdit)
         lineLayout.addWidget(okButton)
         lineLayout.addWidget(cancelButton)
         #lineLayout.insertSpacing(-1,700)
         mainLayout = QtGui.QVBoxLayout()
         mainLayout.addLayout(lineLayout)
         mainLayout.addWidget(self.imageLabel)
         self.setLayout(mainLayout)
  --
cheers Joachim


More information about the PyQt mailing list