Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image is not Displaying at center in QtForm

Tags:

qt

Hi I am using QLabel to show an image in QtForm. My code goes like this

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);

but the image is displaying at the left corner can any one suggest me to bring the image to centre to the form

like image 372
Sharanabasu Angadi Avatar asked Feb 18 '23 10:02

Sharanabasu Angadi


1 Answers

I got solution,

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);
like image 57
Sharanabasu Angadi Avatar answered Mar 03 '23 14:03

Sharanabasu Angadi