How to make the image take up 100% of the screen. pyqt5 -python

0

I have an image and I need it to occupy 100%, it will be the bottom of my program, how to proceed?

from PyQt5 import QtWidgets, QtGui
import sys

class Hello_World(QtWidgets.QWidget):
    def __init__(self):
        super(Hello_World, self).__init__()
        self.setWindowTitle("Olá mundo!")
        self.setGeometry(200,200,700,500)
        self.setStyleSheet("Background-Color: #d9b3ff;")

        self.texto = QtWidgets.QLabel(self)
        self.texto.setPixmap(QtGui.QPixmap("Imagens/fundo.jpg"))

if __name__=="__main__":
    app = QtWidgets.QApplication(sys.argv)
    janela = Hello_World()
    janela.show()
    sys.exit(app.exec_())
    
asked by anonymous 08.03.2018 / 17:34

1 answer

1

You can scale the image, and use it as the background palette:

   oImage = QImage("fundo.png")
   sImage = oImage.scaled(QSize(700,500)) #use o tamanho do fundo
   palette = QPalette()
   palette.setBrush(10, QBrush(sImage))
   # esse 10 acima é a propriedade Window role, veja o manual da Qt
   self.setPalette(palette)

This avoids the need to "improvise" a label background, and shifts the responsibility of the design to the right place (the "painting" of the background).

If you want the size to match the resize of the window, just change oImage.scaled(QSize(700,500)) to oImage.scaled(self.size()) , or preferably do it in SIGNAL("resized()") automatically.

  

link

    
08.03.2018 / 17:55