Setting Position of Image in main Window, QPixmap

前端 未结 1 724
醉话见心
醉话见心 2021-01-28 01:45

im using QPixmap to load image and set the position. Image loads in my main window but the position of image is not setting i used setPos but didn\'t happen anythin

相关标签:
1条回答
  • 2021-01-28 02:14

    The following concepts must be clear:

    • QPixmap is not a visual element but a container for the bits that make up the image so they don't have any setPos() method (recommendation: check the Qt docs).

    • The visual element that shows the content of the QPixmap in your code is the QLabel so you must set the position to that widget, but in this case the OP is using layouts that aim to manage the geometry (position and size) so you should not use it if you want to set it manually.

    def InitWindow(self):
        self.setWindowIcon(QtGui.QIcon("icon.png"))
        self.setWindowTitle(self.title)
        self.setStyleSheet("background-color:#202020")
        self.setGeometry(self.left, self.top, self.width, self.height)
    
        labelImage = QLabel(self)
        pixmap = QPixmap("mario.png")
        pixmap = pixmap.scaled(50, 50, QtCore.Qt.KeepAspectRatio)
        labelImage.setPixmap(pixmap)
        labelImage.move(100, 100)
    
        self.show()
    0 讨论(0)
提交回复
热议问题