图像未以QT格式显示在中心
您好,我正在使用QLabel以QtForm显示图像。 我的代码是这样的图像未以QT格式显示在中心,qt,Qt,您好,我正在使用QLabel以QtForm显示图像。 我的代码是这样的 QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *hLayout = new QHBoxLayout; layout->setMargin(5); QLabel *imageLabel = new QLabel; QPixmap pixmap("/images/test.jpg"); imageLabel->setPixmap(pixmap); imageLa
QVBoxLayout *layout = new QVBoxLayout;
QHBoxLayout *hLayout = new QHBoxLayout;
layout->setMargin(5);
QLabel *imageLabel = new QLabel;
QPixmap pixmap("/images/test.jpg");
imageLabel->setPixmap(pixmap);
imageLabel->setMask(pixmap.mask());
imageLabel->setMinimumSize(160, 160);
imageLabel->resize(500, 320);
layout->addWidget(imageLabel,0,Qt::AlignTop | Qt::AlignCenter);
hLayout->addItem(layout);
widget->setLayout(hLayout);
scrollArea->setWidget(widget);
setCentralWidget(scrollArea);
但是图像显示在左角,有人能建议我将图像置于表单的中心位置吗更改QLabel内容的对齐方式:
imageLabel->setAlignment(Qt::AlignCenter);
我找到了解决办法
QPixmap pixmap("images/test.png");
imageLabel->setPixmap(pixmap);
imageLabel->setMinimumSize(160, 160);
imageLabel->resize(500, 320);
imageLabel->setAlignment(Qt::AlignCenter);
scrollArea->setWidget(widget);
setCentralWidget(imageLabel);
如果
setAlignment
功能不能单独工作,请将其与setizepolicy
一起使用
imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
imageLabel->setAlignment(Qt::AlignCenter);
发布一个打印屏幕,这样我们就可以看到它看起来是什么样子了。请不要发布裸代码,还包括对您正在做的事情的解释。