A most effective way of conveying messages to users is the use of dialogue, like a pop-up window. In this post, we will go through several ways of displaying messages.

Information Dialogue

    def createConnects(self):
        self.actionAbout.triggered.connect(self.showInfoDialogue)
    
    def showInfoDialogue(self):
        QtWidgets.QMessageBox.information(self,
            "This is an info message",
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\
            Nullam justo eros, feugiat nec rhoncus id, dapibus vel \
            libero. Quisque finibus semper erat sed hendrerit. Cras \
            ultrices elit et leo dictum mattis. Vestibulum iaculis \
            est eget ligula pharetra suscipit. ")

Question Dialogue

    def createConnects(self):
        self.actionAbout.triggered.connect(self.showInfoDialogue)
    
    def showInfoDialogue(self):
        status = QtWidgets.QMessageBox.question(self,
            "This is an info message",
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\
            Nullam justo eros, feugiat nec rhoncus id, dapibus vel \
            libero. Quisque finibus semper erat sed hendrerit. Cras \
            ultrices elit et leo dictum mattis. Vestibulum iaculis \
            est eget ligula pharetra suscipit. ",
            QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
        if (status == QtWidgets.QMessageBox.Yes):
           print("Clicked Yes")
        else:
           print("Clicked No")

File and Folder Dialogue

This function opens a file and shows the image.

    def createConnects(self):
        self.actionAbout.triggered.connect(self.fileOpen)

    def fileOpen(self):
        name = QFileDialog.getOpenFileName(self, 'Open File')
        #print(name)
        self.image = QtGui.QImage(name[0])
        pixmap = QtGui.QPixmap(self.image)
        self.lbl.setPixmap(pixmap.scaled(self.lbl.size() , QtCore.Qt.KeepAspectRatio , QtCore.Qt.SmoothTransformation))

Leave a comment

Your email address will not be published. Required fields are marked *