Important: Please read the Qt Code of Conduct -

QLabel show Image problem

  • I want to get image from opencv capture and show it on QLabel frame by frame. Now i use a timer to refresh ui

    this->timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(updatePicture()));
    void FaceCamera::updatePicture()
    	cap >> this->image;
    	showMatOnQLabel(image, ui.cameraLabel);
    void FaceCamera::showMatOnQLabel(cv::Mat mat, QLabel *qlabel)
    	//conversion from Mat to QImage
    	if (mat.empty())
    	cv::Mat dest;
    	cv::cvtColor(mat, dest, CV_BGR2RGB);
    	QImage imageFromMat = QImage((uchar*), dest.cols, dest.rows, dest.step, QImage::Format_RGB888);
    	QImage qimage = imageFromMat.scaled(QSize(qlabel->width(), qlabel->height()), Qt::AspectRatioMode::KeepAspectRatio);
    	//show QImage using QLabel

    it can works, but if i directly get frame in main thread one by one and showMatOnQLabel,
    it will not show image util the last frame i get.

    why this happens ? plese help me

    thx : ]

    from beijing

  • Try adding qlabel->repaint(); after qlabel->setPixmap

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    At what speed are you triggering the timer ?

Log in to reply