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
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With