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 widget expanding to both sides
Forum Updated to NodeBB v4.3 + New Features

Window widget expanding to both sides

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 5.9k 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.
  • D Offline
    D Offline
    deisik
    wrote on 21 Apr 2017, 20:08 last edited by deisik
    #1

    I want to shrink and expand a QWidget in both directions (say, from center to right and left). I can programatically resize the widget and then move it in the opposite direction by half the resize value but that causes terrible flickering (even if I set updatesEnabled to false before resizing and moving). As an option, I could increment the widget size by 1 if it was possible to shrink or expand a widget from both right and left sides. Right now if I change the size of the widget it grows (or shrinks) only from the right side. Is it possible to change size while locking the widget at the right side?

    A 1 Reply Last reply 21 Apr 2017, 22:54
    0
    • D deisik
      21 Apr 2017, 20:08

      I want to shrink and expand a QWidget in both directions (say, from center to right and left). I can programatically resize the widget and then move it in the opposite direction by half the resize value but that causes terrible flickering (even if I set updatesEnabled to false before resizing and moving). As an option, I could increment the widget size by 1 if it was possible to shrink or expand a widget from both right and left sides. Right now if I change the size of the widget it grows (or shrinks) only from the right side. Is it possible to change size while locking the widget at the right side?

      A Offline
      A Offline
      ambershark
      wrote on 21 Apr 2017, 22:54 last edited by
      #2

      @deisik I'm pretty confused based on your description. If you could show with an image or explain it a bit clearer we should be able to help.

      My initial though is just use a spacer in your layout to squish it on the side you don't want expanding. But then I realized you may not even be using a layout for your widget.

      So I'll wait to see what you actually need before I offer some solutions. :)

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      D 1 Reply Last reply 22 Apr 2017, 06:21
      0
      • A ambershark
        21 Apr 2017, 22:54

        @deisik I'm pretty confused based on your description. If you could show with an image or explain it a bit clearer we should be able to help.

        My initial though is just use a spacer in your layout to squish it on the side you don't want expanding. But then I realized you may not even be using a layout for your widget.

        So I'll wait to see what you actually need before I offer some solutions. :)

        D Offline
        D Offline
        deisik
        wrote on 22 Apr 2017, 06:21 last edited by deisik
        #3

        @ambershark

        I'm changing the size of a widget (which is a window) since controls inside this window are expanding to fit their contents. I'm only making it wider or narrower (i.e. change only the window's width). But whenever I change its width (programatically), the window grows only to the right. I want it to grow in both directions, to the left and to the right from the center. I can somewhat emulate this functionality by moving the widget at first to the left by 5 pixels (if I want to increase its width by, say, 10 pixels), and then resizing it by 10 pixels. But this produces flickering at window edges. If there is no such way (to make the window expand in both directions at once), I could increase its width by 1 pixel to the right and to the left alternately until I get the desired width. But for that I should know how to make the window grow from right to left, i.e. increase in width at the left side (by default it increases only at the right side)

        M 1 Reply Last reply 22 Apr 2017, 07:07
        0
        • D deisik
          22 Apr 2017, 06:21

          @ambershark

          I'm changing the size of a widget (which is a window) since controls inside this window are expanding to fit their contents. I'm only making it wider or narrower (i.e. change only the window's width). But whenever I change its width (programatically), the window grows only to the right. I want it to grow in both directions, to the left and to the right from the center. I can somewhat emulate this functionality by moving the widget at first to the left by 5 pixels (if I want to increase its width by, say, 10 pixels), and then resizing it by 10 pixels. But this produces flickering at window edges. If there is no such way (to make the window expand in both directions at once), I could increase its width by 1 pixel to the right and to the left alternately until I get the desired width. But for that I should know how to make the window grow from right to left, i.e. increase in width at the left side (by default it increases only at the right side)

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 22 Apr 2017, 07:07 last edited by
          #4

          @deisik

          hi
          Did you try with setGeometry
          http://doc.qt.io/qt-5/qwidget.html#geometry-prop

          it will set both position and size in one go. so that might prevent the flickering.

          I assume i understand you correctly and u want a resize where BOTH left and right are increased as some
          drawing apps can do.

          D 1 Reply Last reply 22 Apr 2017, 07:38
          2
          • M mrjj
            22 Apr 2017, 07:07

            @deisik

            hi
            Did you try with setGeometry
            http://doc.qt.io/qt-5/qwidget.html#geometry-prop

            it will set both position and size in one go. so that might prevent the flickering.

            I assume i understand you correctly and u want a resize where BOTH left and right are increased as some
            drawing apps can do.

            D Offline
            D Offline
            deisik
            wrote on 22 Apr 2017, 07:38 last edited by deisik
            #5

            @mrjj

            setGeometry() doesn't work as intended, it moves the window but it doesn't change its width since the window keeps its minimum size (which it should). So the only way to actually change the window width is to change it by using setMinimumWidth(). In this way, I still have to first move the window and then change its minimum width (but that produces flickering)

            In fact, I don't want both sides to get increased in some form of animation, I just want to avoid flickering when window is expanded or shrunk to its final width with its center remaining in the same position (+/-1 pixel)

            D 1 Reply Last reply 22 Apr 2017, 11:42
            0
            • D deisik
              22 Apr 2017, 07:38

              @mrjj

              setGeometry() doesn't work as intended, it moves the window but it doesn't change its width since the window keeps its minimum size (which it should). So the only way to actually change the window width is to change it by using setMinimumWidth(). In this way, I still have to first move the window and then change its minimum width (but that produces flickering)

              In fact, I don't want both sides to get increased in some form of animation, I just want to avoid flickering when window is expanded or shrunk to its final width with its center remaining in the same position (+/-1 pixel)

              D Offline
              D Offline
              deisik
              wrote on 22 Apr 2017, 11:42 last edited by deisik
              #6

              It seems that I have managed to employ setGeometry() in a useful way by calling setMinimumWidth() with the new smaller width of the window before calling setGeometry() when I need to shrink the window, and by calling setMaximumWidth() with the new bigger width and then calling setGeometry() when I want the window to grow. Flickering noticeably diminished, so I think I can safely mark this question as solved

              A 1 Reply Last reply 23 Apr 2017, 01:09
              2
              • D deisik
                22 Apr 2017, 11:42

                It seems that I have managed to employ setGeometry() in a useful way by calling setMinimumWidth() with the new smaller width of the window before calling setGeometry() when I need to shrink the window, and by calling setMaximumWidth() with the new bigger width and then calling setGeometry() when I want the window to grow. Flickering noticeably diminished, so I think I can safely mark this question as solved

                A Offline
                A Offline
                ambershark
                wrote on 23 Apr 2017, 01:09 last edited by
                #7

                @deisik Another thing you can try is to use an animation to change the size of the window. This will prevent the flicker. Or at least make it nice looking. ;)

                Qt has some really nice animation ability you'd specifically want QPropertyAnimation to animate on size and position properties.

                My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                D 1 Reply Last reply 23 Apr 2017, 01:52
                0
                • A ambershark
                  23 Apr 2017, 01:09

                  @deisik Another thing you can try is to use an animation to change the size of the window. This will prevent the flicker. Or at least make it nice looking. ;)

                  Qt has some really nice animation ability you'd specifically want QPropertyAnimation to animate on size and position properties.

                  D Offline
                  D Offline
                  deisik
                  wrote on 23 Apr 2017, 01:52 last edited by deisik
                  #8

                  @ambershark

                  I have already got rid of flickering completely by resizing the window in a cycle by just one pixel at a time and then calling repaint() after each iteration. Expanding window works like a charm (no flickering whatever), but shrinking the top window leaves black vertical bars on the background (it doesn't get repainted in the process) at the sides of the window until the window is fully resized (then they vanish). How can I get rid of the them (without explicitly calling repaint() on the background widgets)? When I manually resize the window with mouse, the background get updated in real time, so there should be a way

                  A 1 Reply Last reply 23 Apr 2017, 04:22
                  0
                  • D deisik
                    23 Apr 2017, 01:52

                    @ambershark

                    I have already got rid of flickering completely by resizing the window in a cycle by just one pixel at a time and then calling repaint() after each iteration. Expanding window works like a charm (no flickering whatever), but shrinking the top window leaves black vertical bars on the background (it doesn't get repainted in the process) at the sides of the window until the window is fully resized (then they vanish). How can I get rid of the them (without explicitly calling repaint() on the background widgets)? When I manually resize the window with mouse, the background get updated in real time, so there should be a way

                    A Offline
                    A Offline
                    ambershark
                    wrote on 23 Apr 2017, 04:22 last edited by
                    #9

                    @deisik My guess here is that you are sending too many messages to the event queue so the background widgets basically get starved while you resize. You can slow down your messages or just explicitly allow other messages to be processed during your resizing.

                    You really should check out that property animation though. It does exactly what you want but without having to send 100 messages to resize a window. ;)

                    My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                    D 1 Reply Last reply 23 Apr 2017, 08:25
                    0
                    • A ambershark
                      23 Apr 2017, 04:22

                      @deisik My guess here is that you are sending too many messages to the event queue so the background widgets basically get starved while you resize. You can slow down your messages or just explicitly allow other messages to be processed during your resizing.

                      You really should check out that property animation though. It does exactly what you want but without having to send 100 messages to resize a window. ;)

                      D Offline
                      D Offline
                      deisik
                      wrote on 23 Apr 2017, 08:25 last edited by deisik
                      #10

                      @ambershark

                      I'm not sure that the underlying widgets will get updated if I use QPropertyAnimation for resizing widgets. Can you guarantee that , i.e. they will be receiving the update signals when I shrink the top window using this method (I just don't want to waste my time only to get back to square one)? I remember some method which allowed using bitmaps from memory (i.e. not actual redrawing) for updating certain regions that get exposed during some resize operations. Can anyone chime in on this?

                      A 1 Reply Last reply 23 Apr 2017, 22:43
                      0
                      • D deisik
                        23 Apr 2017, 08:25

                        @ambershark

                        I'm not sure that the underlying widgets will get updated if I use QPropertyAnimation for resizing widgets. Can you guarantee that , i.e. they will be receiving the update signals when I shrink the top window using this method (I just don't want to waste my time only to get back to square one)? I remember some method which allowed using bitmaps from memory (i.e. not actual redrawing) for updating certain regions that get exposed during some resize operations. Can anyone chime in on this?

                        A Offline
                        A Offline
                        ambershark
                        wrote on 23 Apr 2017, 22:43 last edited by
                        #11

                        @deisik Yea the animation just animates the change in the window properties. It doesn't change how those property changes work. So the resize will affect the contained widgets just like any other resize without animation.

                        But don't get me wrong if you have a working solution and don't want to try to find a more efficient one then don't worry about it. If you have time you may want to branch your code and play with the property animation to see if it can make it more fluid for you. Plus it will look cool. Then if it works and you like it, merge it back into your master branch, or just nuke the feature branch if you don't like the animation.

                        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                        D 1 Reply Last reply 24 Apr 2017, 04:48
                        0
                        • A ambershark
                          23 Apr 2017, 22:43

                          @deisik Yea the animation just animates the change in the window properties. It doesn't change how those property changes work. So the resize will affect the contained widgets just like any other resize without animation.

                          But don't get me wrong if you have a working solution and don't want to try to find a more efficient one then don't worry about it. If you have time you may want to branch your code and play with the property animation to see if it can make it more fluid for you. Plus it will look cool. Then if it works and you like it, merge it back into your master branch, or just nuke the feature branch if you don't like the animation.

                          D Offline
                          D Offline
                          deisik
                          wrote on 24 Apr 2017, 04:48 last edited by deisik
                          #12

                          @ambershark

                          I am talking about the widgets that are not part of the resized window. If I shrink the window the areas that were covered by this widow become exposed. Will they get updated in real time? That's the issue I have now. The widgets that were hidden are not updated during the resize operation. Their parts (from left and right) are shown as black bars until the resize operation is over. I can update them by sending signals to them but it is slow because whole widget gets updated while I need updated only a small part of it which becomes visible during the resize operation

                          I'm not sure that QPropertyAnimation will update them either

                          A 1 Reply Last reply 24 Apr 2017, 05:25
                          0
                          • D deisik
                            24 Apr 2017, 04:48

                            @ambershark

                            I am talking about the widgets that are not part of the resized window. If I shrink the window the areas that were covered by this widow become exposed. Will they get updated in real time? That's the issue I have now. The widgets that were hidden are not updated during the resize operation. Their parts (from left and right) are shown as black bars until the resize operation is over. I can update them by sending signals to them but it is slow because whole widget gets updated while I need updated only a small part of it which becomes visible during the resize operation

                            I'm not sure that QPropertyAnimation will update them either

                            A Offline
                            A Offline
                            ambershark
                            wrote on 24 Apr 2017, 05:25 last edited by
                            #13

                            @deisik said in Window widget expanding to both sides:

                            I'm not sure that QPropertyAnimation will update them either

                            Yea I'm not sure either. Only way to find out is to try. I didn't realize you were talking about underneath widgets. They should get updated though on my sizing/animating windows I don't see any "black bars". So I'd give it about an 80% change of working. ;)

                            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                            1 Reply Last reply
                            0

                            4/13

                            22 Apr 2017, 07:07

                            9 unread
                            • Login

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