I get an error with setGeometry
in a very simple program in Qt5.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel* m_photo = new QLabel;
m_photo->setPixmap(QPixmap("test.jpg"));
m_photo->show();
return a.exec();
}
Error: setGeometry: Unable to set geometry 6x16+640+300 on QWidgetWindow/'QLabelClassWindow'. Resulting geometry: 160x16+640+300 (frame: 9, 38, 9, 9, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).
I see Qt adding custom widget to a layout, but I did not understand the comment.
What am I doing wrong?
Probably you get this error because you don't use
setGeometry()
, you should set geometry yourself. Try this:Better way: label should have same size as picture. To do this you can use
QPixmap
methodwidth()
andheight
Edit.
I understood why you get this error. It is very simple, your picture doesn't load! Why? Very simple too: probably your picture(
test.jpg
) was putted near exe file, but Qt doesn't see this file(because Qt use another build directory)Solution: put
test.jpg
in correct directory or set pixmap full path(ad I do"G:/2/test.jpg"
for example). Also use this code: check is your picture load successfully.Is it work now?