Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt setPixmap()未动态使用setGeometry()_C++_Qt - Fatal编程技术网

C++ Qt setPixmap()未动态使用setGeometry()

C++ Qt setPixmap()未动态使用setGeometry(),c++,qt,C++,Qt,我正在实现一个类似于小标签的东西,以显示随鼠标移动的图像细节。我用opencv完成了鼠标移动事件信号和图像放大处理 接收鼠标移动事件并更新标签位置和图像数据的插槽 void CameraView::updateMouseCurcor() { if(superres_mode) { label_x=ui->frameLabel->getMouseCursorPos().x(); label_y=ui->frameLabel->

我正在实现一个类似于小标签的东西,以显示随鼠标移动的图像细节。我用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::frommage(smallPic))我可以看到我的标签文本与鼠标正确匹配。

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

如果我注释掉
label_3->setPixmap(QPixmap::frommage(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);

尝试给出图像的宽度和高度,而不是窗口宽度和窗口高度。设置标签的pixmap后设置geometry。

WINDOW_WIDTH和WINDOW_HEIGHT是定义值(此处未显示),我尝试将它们设置为特殊int,如100、80,并在设置pixmap后设置几何体。试着给出图像的宽度和高度,而不是100,80。图像的宽度和高度就是窗口的宽度,窗口的高度,我制作了这个尺寸的opencv垫子。