查看完整版本: [-- 布局中qlabel显示图片后大小改变的问题 --]

QTCN开发网 -> Qt基础编程 -> 布局中qlabel显示图片后大小改变的问题 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

panan2000 2018-03-13 14:57

布局中qlabel显示图片后大小改变的问题

我把4个qlabel放到一个gridlayout下面,Stretch都是1:1.然后将其中一张贴图

QFileInfo fileInfo("d:/1.png");
if(fileInfo.isFile())
{
        QPixmap img("d:/1.png");
        img.scaled(ui.labPic_1->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
        ui.labPic_1->setPixmap(img);        
}


之后比例就成这样了,label1贴图之后就放大了。
[attachment=18560]
但是贴3个label或者4个的时候比例是正常的,
[attachment=18559]
setStretch用了也没反应。。
大神们能帮忙看看怎么能贴一张图的时候固定layout的比例吗?

yuyu414 2018-03-14 09:18
    for (int i = 0; i < rowCount; i++)
    {
        ui->gridLayout->setRowStretch(i, 1);
    }
    for (int i = 0; i < columnCount; i++)
    {
        ui->gridLayout->setColumnStretch(i, 1);
    }
rowcount和columncount为gridlayout的行和列

panan2000 2018-03-16 08:38
yuyu414:    for (int i = 0; i < rowCount; i++)
    {
        ui->gridLayout->setRowStretch(i, 1);
    }
    for (int i = 0; i < columnCo .. (2018-03-14 09:18) 

setStretch之前就试了,没有用。
图片分辨率过大的时候图片qlabl就会放大。。
我现在是通过resizeEvent对他进行控制的


查看完整版本: [-- 布局中qlabel显示图片后大小改变的问题 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled