嗨,我正在使用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);
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);
Run Code Online (Sandbox Code Playgroud)
但图片显示在左上角,有人可以建议我将图片放在表格的中心吗
我有解决办法
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3187 次 |
| 最近记录: |