QImage
-
Hi friends,
I am Qlabel in Qwidget to display image but in Qlabel image left side gap is more than right size how to center can anbody tell the solution.
const QPixmap pix = QPixmap::fromImage(image); const QSize size = ui->Image_Label->size(); //modified on 23/10/2018 ui->Image_Label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); ui->Image_Label->setPixmap(pix.scaled(size,Qt::KeepAspectRatio));
-
Hi
When do you call the code ?
The ui->Image_Label should be fully visible before you take its
size as layout calculation is deferred until widget is visible. -
In Qwiget i put QLabel with gridlayout in ui form at starting i am showing widget.
-
In Qwiget i put QLabel with gridlayout in ui form at starting i am showing widget.
@satyanarayana143
"at starting" means in Mainwindows constructor ?
Try to do same code from a button and see if it then works as expected.
if it does, it means, you are doing taking size of Label when its not fully layouted yet. -
I am displaying when checkbox checked in ui as above image.
-
I am displaying when checkbox checked in ui as above image.
@satyanarayana143
So when you run code, the QLabel is fully visible ?
Sorry , i cannot guess what else could be wrong.
It centers as expected here
-
@satyanarayana143
So when you run code, the QLabel is fully visible ?
Sorry , i cannot guess what else could be wrong.
It centers as expected here
can you send the code
-
can you send the code