Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Different behavoir for a "Creator made app" and a "manual coded app"? How comes.
Qt 6.11 is out! See what's new in the release blog

Different behavoir for a "Creator made app" and a "manual coded app"? How comes.

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 892 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ademmlerA Offline
    ademmlerA Offline
    ademmler
    wrote on last edited by ademmler
    #1

    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
      correct.png

    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

    wrong.png

    Example code you can get here:
    http://files.lacunasolutions.com/various/ImageViewerBogo.zip

    You 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);
    
    //-------------------------------------------------------------------------
    
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #4

      In the designer you have the widgetResizable property set to true which causes the stretching, as the label resizes to fit the scroll area. From code you're leaving that at default, which is false, and so the label doesn't resize and scroll bars show up.

      ademmlerA 1 Reply Last reply
      5
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #2

        @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.

        C++ is a perfectly valid school of magic.

        ademmlerA 1 Reply Last reply
        0
        • fcarneyF fcarney

          @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.

          ademmlerA Offline
          ademmlerA Offline
          ademmler
          wrote on last edited by
          #3

          @fcarney I see and respect your point.In order to learn more about the Creator I am still curious.

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #4

            In the designer you have the widgetResizable property set to true which causes the stretching, as the label resizes to fit the scroll area. From code you're leaving that at default, which is false, and so the label doesn't resize and scroll bars show up.

            ademmlerA 1 Reply Last reply
            5
            • Chris KawaC Chris Kawa

              In the designer you have the widgetResizable property set to true which causes the stretching, as the label resizes to fit the scroll area. From code you're leaving that at default, which is false, and so the label doesn't resize and scroll bars show up.

              ademmlerA Offline
              ademmlerA Offline
              ademmler
              wrote on last edited by ademmler
              #5

              *@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

              Chris KawaC 1 Reply Last reply
              0
              • ademmlerA ademmler

                *@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

                Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by
                #6

                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.

                ademmlerA 1 Reply Last reply
                3
                • Chris KawaC Chris Kawa

                  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.

                  ademmlerA Offline
                  ademmlerA Offline
                  ademmler
                  wrote on last edited by
                  #7

                  @Chris-Kawa

                  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

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved