QHBoxLayout cover QWidget with image
-
Hello, it's my first post here so thanks ahead for any help.
I have a QWidget that hold image and QHBoxLayout that hold other componnents like QPushButton, QSlider etc..
Next i'm try to add this to QDialog witch QHBoxLayout.
I didn't got any warning or error, but in QDialog i only see part of Image. The other-half is covered by QHBoxLayout, i can see full picture only if i drag and move QDialog to full screen.I also add screenshot for beter explation.
-
hi and welcome to the forums.
Is that QHBoxLayout one of the red ones in Designer or did you make it all from code?It sounds like the dialog itself does not have a layout so it would auto-scale both the image and the "buttons" layout.
-
@mrjj
"Is that QHBoxLayout one of the red ones in Designer or did you make it all from code?"All created dynamically in code
"It sounds like the dialog itself does not have a layout so it would auto-scale both the image and the "buttons" layout."
Probably no, i'm using QHLayout to organize everything in QDialog.
(Simplificed example of code)
/* create QButtons, QSpin etc.... */ columnLayout = new QVBoxLayout; /* Adding button to QVBoxLayout... */ widget = new QImageWidget; mainLayout = new QHBoxLayout(); mainLayout->addWidget(widget); mainLayout->addLayout(columnLayout); /*seting up QDialog */ windowWidget = new QDialog; windowWidget->setLayout(mainLayout);
Note: Image Widget is my own clss that inherit from QWidget and override paintEvent to simply draw QImage.
I also finded out that if i add QVBoxLayout to QWidget and then QWidget to QDialog instead of just adding QVBoxLayout to QDialog - it's working good. But still i would like to understand why simple QWidget dosnt work.
-
Hi
It's most likely due to the QVBoxLayout and the size policy of the QImageWidget.
You can try overriding sizeHint and return the size of the image.