Different behavoir for a "Creator made app" and a "manual coded app"? How comes.
-
Hi QT friends and folks.
I play with an already existing example of "image viewer" and I noticed some strange differences in the same app,
bay changing the way of coding? Can somebody point me to the solution pls:A) When I create the UI by coding manually the app has the desired behavoir:
- keep aspect ratio
- activate scroll bars
- don't scale the image
When I use QT creator to place needed elements the behavoir changes:
- no scrollbars are activated
- the image is skewed (aspect ration is dismissed)
- the image is scaled
Example code you can get here:
http://files.lacunasolutions.com/various/ImageViewerBogo.zipYou can swop the beaver in this section in imageviewer.cpp starting at line 29.
//-------------------------------------------------------------------------
//Swop next line with the next one 29 -> 30 //imageLabel = ui->imageLabel; imageLabel = new QLabel; imageLabel->setBackgroundRole(QPalette::Base); imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); imageLabel->setScaledContents(true); //Swop next line with the two following ones 38 -> 39 + 40 //scrollArea = ui->scrollArea; scrollArea = new QScrollArea; scrollArea->setWidget(imageLabel); //-------------------------------------------------------------------------
-
In the designer you have the
widgetResizable
property set totrue
which causes the stretching, as the label resizes to fit the scroll area. From code you're leaving that at default, which isfalse
, and so the label doesn't resize and scroll bars show up. -
@ademmler said in Different behavoir for a "Creator made app" and a "manual coded app"? How comes.:
swop the beaver
Anyway, its most likely options that are not selected to make the output the same. I really don't like the Creator interface and prefer to code everything. I would rather know the code than know the editor. Sorry I can't be more helpful.
-
In the designer you have the
widgetResizable
property set totrue
which causes the stretching, as the label resizes to fit the scroll area. From code you're leaving that at default, which isfalse
, and so the label doesn't resize and scroll bars show up. -
*@Chris-Kawa thx so much. This hint helped and if I change it all is fine.
Now I have put some more elements into the UI - with Creator. And agin the behavior is strange.- Image is skewed again
- Second area with listView and Pushbutton does not appear.
Would you help me again please? The sample you can get here:
http://files.lacunasolutions.com/various/ImageViewerBogo-mod2.zip*I found the answer to this myself.
in order to show all elements I had to remove this in image viewer.cpp:
//scrollArea->setWidget(imageLabel);thx and greetings
Alexander -
Image is skewed again
This is because you've enabled image scaling in the label:
imageLabel->setScaledContents(true);
Second area with listView and Pushbutton does not appear.
This is because you're overwriting your contents with one of the widgets:
setCentralWidget(scrollArea);
Remove both of these lines.
-
Dear Chris, thx again. this solved a lot. I have incorporated your recommendations.
Now the image gets "cropped". You may tell me again what's wrong or why this happens.thx again in advance.
The actual test: http://files.lacunasolutions.com/various/ImageViewerBogo-mod3.zip