繁体   English   中英

Qt setPixmap()不适用于setGeometry()

[英]Qt setPixmap() not working with setGeometry() on the fly

我正在实现类似小标签的功能,以显示随鼠标移动的图像细节。 我完成了鼠标移动事件信号并使用opencv放大了图像处理。

接收鼠标移动事件并更新标签位置和图像数据的插槽。

void CameraView::updateMouseCurcor()
{
    if(superres_mode)
    {
        label_x=ui->frameLabel->getMouseCursorPos().x();
        label_y=ui->frameLabel->getMouseCursorPos().y();

// opencv based function to produce the zoom in detailed image src
        toyFuncion(input,output);  

        label_x+=ui->label->width();
        ui->label_3->setGeometry(label_x,label_y,WINDOW_WIDTH,WINDOW_HEIGHT);

        smallPic = QImage((const unsigned char*)(output.data),output.cols,output.rows,output.cols*output.channels(),QImage::Format_RGB888);
        ui->label_3->setPixmap(QPixmap::fromImage(smallPic));
    }
}

问题是,带有图像的小标签没有显示。

如果我注释掉label_3->setPixmap(QPixmap::fromImage(smallPic)); 我可以看到我的标签文本正确地与鼠标配合使用。 在此处输入图片说明

我已调试并检查小图像数据是否完全正常。 我试图在ui->label->setPixmap(QPixmap::fromImage(smallPic));旁边的另一个标签中显示它ui->label->setPixmap(QPixmap::fromImage(smallPic)); 在此处输入图片说明

如果我注释掉label_3->setPixmap(QPixmap::fromImage(smallPic)); 并在构造函数中设置标签,例如:

cv::Mat temp;
    cv::resize(src,temp,cv::Size(WINDOW_WIDTH,WINDOW_HEIGHT));
    smallPic = QImage((const unsigned char*)(temp.data),temp.cols,temp.rows,temp.cols*temp.channels(),QImage::Format_RGB888);

    ui->label_3->setPixmap(QPixmap::fromImage(smallPic));

    ui->label_3->setScaledContents(true); 

图像显示出来并用鼠标移动得很好。 在此处输入图片说明

我想知道我的实现中出了什么问题,标签的控制层如何以及如何同时更新标签的几何形状和图像。

我想你的问题就在这里

ui->label_3->setGeometry(label_x,label_y,WINDOW_WIDTH,WINDOW_HEIGHT);

尝试提供图像的宽度和高度,而不是WINDOW_WIDTH和WINDOW_HEIGHT。 设置标签的像素图后设置geomtery。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM