Search code examples
qtqtguiqpixmapqlabel

displaying an image in a qlabel which has been promoted to a class


I'm writing a gui application and I must display an image on a label that has been promoted into a class(my_qlabel). I upload the image using a dialog in the other class, and call a function in "my_qlabel" to display it.

void my_qlabel::displayImage(QString filename){
     QPixmap pic (filename);
     //..i dont know the relevant lines i should include here to display....
}

Solution

  • QLabel class has a setPixmap(const QPixmap &) function. Since you are subclassing QLabel class, you can use the same function in your class.

    void my_qlabel::displayImage(QString filename){
        QPixmap pic (filename);
        setPixmap(pic);
    }