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. Window cannot shrink after expanding
Forum Updated to NodeBB v4.3 + New Features

Window cannot shrink after expanding

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 244 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.
  • E Offline
    E Offline
    EtheraelEspeon
    wrote on 2 Jun 2023, 01:58 last edited by
    #1

    (Some background info: I'm using MSVC2019 and C++)

    As above. I'm expanding a window with a label displaying a pixmap, and trying to make the label scale to fit in the window. It works, but after I expand the label, I can only shrink the window until it would make the label shrink.
    The settings on the label:
    9282fd41-301e-49fa-bb4b-b5d4a9dcf08b-image.png
    I assume the issue lies in how I'm setting the label's pixmap, but I can't find another way to make it scale properly.

    // excerpt from the definitions of a utility header
    void utl::setImage(QLabel* label, QImage img)
    {
    	if (img.colorSpace().isValid())	img.convertToColorSpace(QColorSpace::SRgb);
    
    	auto pixmap = QPixmap::fromImage(img);
    	pixmap = pixmap.scaled(label->size(), Qt::AspectRatioMode::KeepAspectRatio);
    
    	label->setPixmap(pixmap);
    }
    
    // excerpt from the definitions of my QMainWindow class
    void DesktopFrontend::resizeEvent(QResizeEvent* resizeEvent)
    {
    	utl::setImage(ui.imageDisplay, currentImage);
    }
    

    I feel like the problem here is relatively trivial, but I've had a lot of difficulty finding good info on how to actually use Qt. Is there a good way to debug this kind of issue?

    P 1 Reply Last reply 2 Jun 2023, 03:28
    0
    • E EtheraelEspeon
      2 Jun 2023, 01:58

      (Some background info: I'm using MSVC2019 and C++)

      As above. I'm expanding a window with a label displaying a pixmap, and trying to make the label scale to fit in the window. It works, but after I expand the label, I can only shrink the window until it would make the label shrink.
      The settings on the label:
      9282fd41-301e-49fa-bb4b-b5d4a9dcf08b-image.png
      I assume the issue lies in how I'm setting the label's pixmap, but I can't find another way to make it scale properly.

      // excerpt from the definitions of a utility header
      void utl::setImage(QLabel* label, QImage img)
      {
      	if (img.colorSpace().isValid())	img.convertToColorSpace(QColorSpace::SRgb);
      
      	auto pixmap = QPixmap::fromImage(img);
      	pixmap = pixmap.scaled(label->size(), Qt::AspectRatioMode::KeepAspectRatio);
      
      	label->setPixmap(pixmap);
      }
      
      // excerpt from the definitions of my QMainWindow class
      void DesktopFrontend::resizeEvent(QResizeEvent* resizeEvent)
      {
      	utl::setImage(ui.imageDisplay, currentImage);
      }
      

      I feel like the problem here is relatively trivial, but I've had a lot of difficulty finding good info on how to actually use Qt. Is there a good way to debug this kind of issue?

      P Offline
      P Offline
      Pl45m4
      wrote on 2 Jun 2023, 03:28 last edited by
      #2

      @EtheraelEspeon said in Window cannot shrink after expanding:

      void DesktopFrontend::resizeEvent(QResizeEvent* resizeEvent)
      {
      utl::setImage(ui.imageDisplay, currentImage);
      }

      In the first place, why you set the image on every resizeEvent?

      I assume the issue lies in how I'm setting the label's pixmap

      Could also be the settings of your parent layout. The sizePolicy is "Expanding". It will expand, but wont shrink further than the initial / content size (which updates every time you set the pixmap)

      It works, but after I expand the label, I can only shrink the window until it would make the label shrink

      Horizontally? Vertically? Or both?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      E 1 Reply Last reply 3 Jun 2023, 06:56
      0
      • P Pl45m4
        2 Jun 2023, 03:28

        @EtheraelEspeon said in Window cannot shrink after expanding:

        void DesktopFrontend::resizeEvent(QResizeEvent* resizeEvent)
        {
        utl::setImage(ui.imageDisplay, currentImage);
        }

        In the first place, why you set the image on every resizeEvent?

        I assume the issue lies in how I'm setting the label's pixmap

        Could also be the settings of your parent layout. The sizePolicy is "Expanding". It will expand, but wont shrink further than the initial / content size (which updates every time you set the pixmap)

        It works, but after I expand the label, I can only shrink the window until it would make the label shrink

        Horizontally? Vertically? Or both?

        E Offline
        E Offline
        EtheraelEspeon
        wrote on 3 Jun 2023, 06:56 last edited by
        #3

        @Pl45m4 said in Window cannot shrink after expanding:

        In the first place, why you set the image on every resizeEvent?

        This was the only way I could find to make the label's contents be resized to fit the window. The images I'm displaying are quite hi-res TIFFs, and at native resolution they can't fit on my 1080p monitor. I assume there's a better way to do this, but I couldn't find one.

        Horizontally? Vertically? Or both?

        Both. Here's a video of the behavior:
        https://youtu.be/pe7nOlxXKcA

        And here's the configuration of another window exhibiting the same behavior
        b2de6ba7-3881-49d8-8e0b-b723585b0c0d-image.png
        19afcd2c-2507-42f8-8329-489e5679376b-image.png

        This is the full form file of that window, in case that's helpful:

        <?xml version="1.0" encoding="UTF-8"?>
        <ui version="4.0">
         <class>PointSelector</class>
         <widget class="QWidget" name="PointSelector">
          <property name="geometry">
           <rect>
            <x>0</x>
            <y>0</y>
            <width>643</width>
            <height>528</height>
           </rect>
          </property>
          <property name="windowTitle">
           <string>Point Selector</string>
          </property>
          <layout class="QVBoxLayout" name="verticalLayout">
           <item>
            <widget class="QLabel" name="imageDisplay">
             <property name="sizePolicy">
              <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
             </property>
             <property name="text">
              <string>No File</string>
             </property>
             <property name="alignment">
              <set>Qt::AlignCenter|Qt::AlignHCenter|Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
             </property>
            </widget>
           </item>
           <item>
            <widget class="Line" name="line">
             <property name="orientation">
              <enum>Qt::Horizontal</enum>
             </property>
            </widget>
           </item>
           <item>
            <layout class="QHBoxLayout" name="horizontalLayout">
             <item>
              <widget class="QLabel" name="label">
               <property name="text">
                <string>Left Click on head | Right Click on tail</string>
               </property>
              </widget>
             </item>
             <item>
              <widget class="QPushButton" name="confirmButton">
               <property name="sizePolicy">
                <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
                 <horstretch>0</horstretch>
                 <verstretch>0</verstretch>
                </sizepolicy>
               </property>
               <property name="minimumSize">
                <size>
                 <width>175</width>
                 <height>0</height>
                </size>
               </property>
               <property name="text">
                <string>Confirm</string>
               </property>
              </widget>
             </item>
            </layout>
           </item>
          </layout>
         </widget>
         <resources/>
         <connections/>
        </ui>
        
        1 Reply Last reply
        0

        1/3

        2 Jun 2023, 01:58

        • Login

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