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. Widget's geometry before first show
Forum Updated to NodeBB v4.3 + New Features

Widget's geometry before first show

Scheduled Pinned Locked Moved General and Desktop
20 Posts 5 Posters 17.0k Views 1 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
    DimanNe
    wrote on last edited by
    #1

    Suppose I have QStackedLayout, and some Widgets in it.
    How can I know geometry (real, not QRect(0,0 640x480)) of given widget before first call QStackedLayout::setCurrentWidget(widget)?

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

      looks like no APIs to make such a call. what is your use case? why isn't QRect() enough?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DimanNe
        wrote on last edited by
        #3

        So, I has several widgets in QStackedLayout. All these widgets are hidden when programme starts. But on button click I want to start animation, in which corresponding widget's geometry() will be changed from button's geometry() to geometry of this widget, when it is shown (and at end of the animation call widget->show()). So, I must know its geometry before first show...
        I think, it can be made by placing (and showing) empty dummy widget, before animation...

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on last edited by
          #4

          You might not need dummy widgets. Have you seen the animation framework examples? You can play with QPropertyAnimation and animate the position, size, rotate and opacity properties and make the transitions look how you want.

          And yes, you can add the widget itself to the layout and obtain the size before the show. the property animation can then take initial value from the button's size and end value will be the widget's size. You can also animate opacity from 0 to 1, so the widget will be hidden first and then fully appear at the end of the animation

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DimanNe
            wrote on last edited by
            #5

            bq. You might not need dummy widgets. Have you seen the animation framework examples? You can play with QPropertyAnimation and animate the position, size, rotate and opacity properties and make the transitions look how you want.

            Yes, of course, I know about QPropertyAnimation, and I use it.
            But I apply it to painter (scale/translate) on which widget draws itself (by widget->render(&p)). I think that I can not apply QPropertyAnimation directly to my widget because it is quite complex and it will look ugly when it will have small sizes during animation. Furthermore, I want to get something looking like KDE animation, while minimizing windows.

            bq. And yes, you can add the widget itself to the layout and obtain the size before the show.

            No, I can not... Yes, I can, but this size (before first show) is not correct - always equals to QRect(0, 0, 640x480)

            1 Reply Last reply
            0
            • ? This user is from outside of this forum
              ? This user is from outside of this forum
              Guest
              wrote on last edited by
              #6

              You mean, before show() if you use something like
              @
              widget->setGeometry(QRect(30,30,200,200);
              @
              it will still show QRect(0,0,640x480) ?

              can you check again and confirm?

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DimanNe
                wrote on last edited by
                #7

                No, after this
                @widget->setGeometry(QRect(30,30,200,200);@
                geometry will become QRect(30,30,200,200)

                But where/how can I know proper values?

                Furthermore,
                "will still show QRect(0,0,640×480) or not after widget->setGeometry(X);" - is NOT the question.
                Qustions is how to find correct X.

                1 Reply Last reply
                0
                • ? This user is from outside of this forum
                  ? This user is from outside of this forum
                  Guest
                  wrote on last edited by
                  #8

                  can you upload your test file, can chk further

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    DimanNe
                    wrote on last edited by
                    #9

                    Test code here
                    "http://pastebin.com/biVYTMvr":http://pastebin.com/biVYTMvr

                    Output is:

                    MainWindow::showEvent: Geometry of second button before show QRect(0,0 640x480)
                    MainWindow::on_Timer_timeout(): Geometry of second button after show QRect(0,0 200x100)

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      danilocesar
                      wrote on last edited by
                      #10

                      Usually, layouts try to respect preferredSize() values, however I'm not used to QStackLayout.

                      I'm remember when I was working with GraphicsLayout that there is no way to know the internal elements sizes before layout's "invalidade":http://doc.trolltech.com/4.6/qgraphicslayout.html#invalidate and "activate":http://doc.trolltech.com/4.6/qgraphicslayout.html#activate

                      The elements still needs to be rearranged.

                      <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
                      Software Engineer

                      1 Reply Last reply
                      0
                      • ? This user is from outside of this forum
                        ? This user is from outside of this forum
                        Guest
                        wrote on last edited by
                        #11

                        As soon as you create the widget, why not use

                        @
                        Stack->widget(1)->setFixedSize(200,100);
                        @

                        or to any other custom size?

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          DimanNe
                          wrote on last edited by
                          #12

                          bq. or to any other custom size?

                          What is the custom size?
                          I do not know PROPER (correct) size. PROPER size = size of widget, when it fits its parent widget (Stack in the example)

                          Of course, I can calculate (how it does Qt layout system) it by myself, but then I must write half of Qt layout system), to take into account indents, different platforms and so on...

                          1 Reply Last reply
                          0
                          • ? This user is from outside of this forum
                            ? This user is from outside of this forum
                            Guest
                            wrote on last edited by
                            #13

                            you are right, calculating the sizes though possible will be a tall order. In your case, you want to animate only on click of a button, at which points I assume all the widgets will be created, laid out in the layout, so will be sized properly.

                            That corresponds to the following in your test code ...

                            @
                            void MainWindow::on_Timer_timeout()
                            {
                            qDebug() << "MainWindow::on_Timer_timeout(): Geometry of second button before animation" << Stack->currentWidget()->geometry();

                              // At this point all widgets are laid out and sized properly, but the widget is still not shown
                              // You can set the initial size and target size.
                            
                              Stack->setCurrentIndex(1);
                              // widget is shown now with initial size... and you can animate at this point?
                            
                              qDebug() << "MainWindow::on_Timer_timeout(): Geometry of second button after show" << Stack->currentWidget()->geometry();
                            

                            }
                            @

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              DimanNe
                              wrote on last edited by
                              #14

                              bq. you want to animate only on click of a button,

                              Yes

                              bq. at which points I assume all the widgets will be created,

                              Yes

                              bq. laid out in the layout,

                              Yes

                              bq. so will be sized properly.

                              No... They all added to QStackedLayout, but not shown. Only one (first of them) shown when app has started. And only after they all are shown though one time, they will have proper size. But at start, only on of them is shown...

                              Since they all has the same size, I think, I can use proper size of this first shown widget.

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                stukdev
                                wrote on last edited by
                                #15

                                QStackedWidget provides a stack of widgets where only one widget is visible at a time.
                                So i think the geometry of all widget if is not specific, it will be the geometry of the QStackedWidget.

                                size of
                                @
                                QStackedWidget->widget(0)->geometry();
                                QStackedWidget->widget(1)->geometry(); @

                                after use
                                @
                                QStackedWidget->setCurrentIndex(number);@

                                is
                                @
                                QStackedWidget->geometry();@

                                But i not understand if this is useful for you or not :)

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  DimanNe
                                  wrote on last edited by
                                  #16

                                  This
                                  widget(0)->geometry();
                                  and this
                                  QStackedWidget->geometry();

                                  almost equal - differs 2-3pixels.

                                  But best solution, imho, is

                                  bq. Since they all has the same size, I think, I can use proper size of this first shown widget.

                                  1 Reply Last reply
                                  0
                                  • ? This user is from outside of this forum
                                    ? This user is from outside of this forum
                                    Guest
                                    wrote on last edited by
                                    #17

                                    [quote author="DimanNe" date="1287502693"]
                                    almost equal - differs 2-3pixels.[/quote]

                                    i think they have to be equal, unless there a margin set?

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      A_n_d_r_e_y
                                      wrote on last edited by
                                      #18

                                      Did you try after creating widget call QWidget::adjustSize()? as recommended here:
                                      http://stackoverflow.com/questions/4963220/qt-how-to-preview-sizes-of-widgets-in-layout-before-a-show

                                      1 Reply Last reply
                                      0
                                      • S Offline
                                        S Offline
                                        Sam
                                        wrote on last edited by
                                        #19

                                        The thread is more than 2 years old.

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          A_n_d_r_e_y
                                          wrote on last edited by
                                          #20

                                          You're right, I saw that ))), but as I understood DimanNe did find good solution. I've come across the same problem and QWidget::adjustSize() works well and looks better as for me. I posted that just for the case if someone like me has the same problem and check QWidget::adjustSize().

                                          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