[Python] How to zoom a picture implemented with QPixmap on pyqt5

Discussão em 'Python' iniciado por Stack, Fevereiro 4, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to zoom in a picture i implemented with QPixmap but nothing works. Here is the way i implemented this. (self.hauteur is a float that represents the height)

    self.label.setPixmap(QPixmap(self.image).scaledToHeight(self.hauteur))


    I've put my label into a layout in order to put it in a scroll widget then.

    self.layout6.addWidget(self.label)


    ...

    self.widget1=QWidget()
    self.widget1.setLayout(self.layout6)
    self.scroll1.setWidget(self.widget1)
    self.tab1.layout.addWidget(self.scroll1,0,1,1,2)


    ...

    self.tab1.setLayout(self.tab1.layout)


    How should I do if i want to build a method that zoom in or zoom out the picture in my window by pushing a button ? I've tried to resize the label but it doesn't work.

    self.action5=QAction(QIcon("Icon/in"),"Zoom in",self)
    self.action5.triggered.connect(self.zoomin)


    ...

    def zoomin(self):
    self.hauteur+=100
    self.label.scaledToHeight(self.hauteur)
    self.update()

    Continue reading...

Compartilhe esta Página