这是我试图用Qlabel解决一个烦人问题的三天 . 我创建了一个程序,用鼠标提取图像内某些特定点的坐标 . 图像被加载到Qscrollarea内的Qlabel内 . 程序有效,但由于QLabel的自动调整大小,坐标出错 . Qlabel的特性是:ScaleContent为true,并且设置为prefeered的verical和horizontal策略 .
在开始我用这种方式加载图像布局:
ui->setupUi(this);
ui->lbl_image_istruction->setScaledContents(true);
ui->txt_instruction->setText( "Please load the image you want to analyze" );
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(ui->label_show);
ui->label_show->setScaledContents(true);
ui->scrollContent->setLayout(layout);
ui->label_show->installEventFilter(this);
我尝试了尺寸为1000x1000的玩具图像 . 程序正确加载图像,Qlabel的大小为1000x1000但是一旦程序启动(我选择图像内的像素),QLabel的尺寸变为982x982,产生像素选择的错误 . 对于instace,应该是499x499的图像中心是479x479 .
似乎垂直和水平的scroolbar减小了图像的大小 .
有没有人对这个问题有任何想法?可能这是一个愚蠢的问题,它很容易解决,但我无法找到解决方案 .
另一个例子 .
void esempio::on_actionNormaleSize_triggered()
{
//---------------------------------------------------------
// code to restore the original size of the image
//---------------------------------------------------------
imagesize = ui->label_show->size();
imagesize.rheight() = imagesize.rheight()*1/scaleFactor;
imagesize.rwidth() = imagesize.rwidth()*1/scaleFactor;
//restoring factor
scaleFactor =1;
ui->label_show->resize(imagesize);
ui->scrollContent->resize(imagesize);
}
通过使用此功能,我想恢复图像的原始大小 . 如果比例因子为1,则尺寸应保持不变,但每次我称之为玩具图像的尺寸都会以这种方式减小 . 1000x1000,982x982,964x964,946x946,928x928等......
谢谢