Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [Solved]QSplitter Animation

    General and Desktop
    3
    13
    5571
    Loading More Posts
    • 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.
    • S
      Saki last edited by

      Hello,
      I get some issue with QSplitter. I have two widgets and I hide one of those by:
      @QList<int> l_sizes;
      l_sizes << width() << 0;
      MySplitter->setSizes(l_sizes);@

      Now I'd like to show the hide one by expand that widget, I have tried QPropertyAnimation, but nothing happened. Could anyone help me with the problem?
      Thanks a lot!!


      Solution:
      Use a QTimeLine to change the QList<int>, and then set it.

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        [quote author="Saki" date="1372316713"]Now I'd like to show the hide one by expand that widget, I have tried QPropertyAnimation, but nothing happened. Could anyone help me with the problem?[/quote]
        Not with the information provided...

        Please post the code for your property animation and your class which you want to animate.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 0
        • S
          Saki last edited by

          [quote author="raven-worx" date="1372317644"][quote author="Saki" date="1372316713"]Now I'd like to show the hide one by expand that widget, I have tried QPropertyAnimation, but nothing happened. Could anyone help me with the problem?[/quote]
          Not with the information provided...

          Please post the code for your property animation and your class which you want to animate.

          [/quote]

          I'm so sorry I forget it...Here is my code:

          @kcicompiledock::kcicompiledock(QWidget *parent):
          QDockWidget(parent)
          {
          //Set Object Name.
          setObjectName(QString("Compile Dock"));

          //Set Dock Style.
          setContentsMargins(0,0,0,0);
          QPalette pal=this->palette();
          //pal.setColor(QPalette::Base,QColor(0x35,0x35,0x35));
          pal.setColor(QPalette::Base,QColor(0x35,0x35,0x35));
          pal.setColor(QPalette::WindowText,QColor(255,255,255));
          pal.setColor(QPalette::Button,QColor(83,83,83));
          pal.setColor(QPalette::Text,QColor(255,255,255));
          pal.setColor(QPalette::ButtonText,QColor(255,255,255));
          this->setPalette(pal);
          setWindowTitle(QString(tr("Compiler")));
          setAllowedAreas(Qt::BottomDockWidgetArea);
          
          //Set Dock Widget and Layout.
          //objCombine=new QWidget(this);
          //objCombine->setContentsMargins(0,0,0,0);
          splCombine=new QSplitter(Qt::Horizontal, this);
          splCombine->setContentsMargins(0,0,0,0);
          
          //Set Text Output.
          compileOutput=new QPlainTextEdit(this);
          compileOutput->setContentsMargins(0,0,0,0);
          compileOutput->setWordWrapMode(QTextOption::NoWrap);
          splCombine->addWidget(compileOutput);
          
          //Set TreeView Controls.
          trevwCompileInfo=new QTreeView(this);
          trevwCompileInfo->setContentsMargins(0,0,0,0);
          pal=trevwCompileInfo->palette();
          pal.setColor(QPalette::Foreground,QColor(255,255,255));
          trevwCompileInfo->setPalette(pal);
          compileInfo=new QStandardItemModel();
          trevwCompileInfo->setGeometry(0,0,0,0);
          splCombine->addWidget(trevwCompileInfo);
          QList<int> l_sizes;
          l_sizes << width() << 0;
          splCombine->setSizes(l_sizes);
          
          setWidget(splCombine);
          

          }

          void kcicompiledock::animeShowError()
          {
          QPropertyAnimation showTrevwAnime(trevwCompileInfo,"geometry");
          QRect startRect=trevwCompileInfo->rect();
          QRect finalRect=startRect;
          finalRect.setWidth(100);
          showTrevwAnime.setStartValue(startRect);
          showTrevwAnime.setEndValue(finalRect);

          showTrevwAnime.start();
          

          }@

          I'd like to animate the QTreeView object, like the code in animeShowError. But I know this code didn't work at all. I don't know how to animate the widget.

          1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators last edited by

            i don't see any QPropertyAnimation in your code?!

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply Reply Quote 0
            • S
              Saki last edited by

              [quote author="raven-worx" date="1372326854"]i don't see any QPropertyAnimation in your code?![/quote]

              Please see LINE #50.

              1 Reply Last reply Reply Quote 0
              • raven-worx
                raven-worx Moderators last edited by

                your animation doesn't work because you create the animation object on the stack...thus it is destroyed right after the method is exited.

                so you should do this instead:
                @
                void kcicompiledock::animeShowError()
                {
                QPropertyAnimation* showTrevwAnime = new QPropertyAnimation(trevwCompileInfo,"geometry");
                QRect startRect=trevwCompileInfo->rect();
                QRect finalRect=startRect;
                finalRect.setWidth(100);
                showTrevwAnime->setStartValue(startRect);
                showTrevwAnime->setEndValue(finalRect);

                showTrevwAnime->start(QAbstractAnimation::DeleteWhenStopped);
                

                }
                @

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply Reply Quote 0
                • S
                  Saki last edited by

                  [quote author="raven-worx" date="1372348188"]your animation doesn't work because you create the animation object on the stack...thus it is destroyed right after the method is exited.

                  so you should do this instead:
                  @
                  void kcicompiledock::animeShowError()
                  {
                  QPropertyAnimation* showTrevwAnime = new QPropertyAnimation(trevwCompileInfo,"geometry");
                  QRect startRect=trevwCompileInfo->rect();
                  QRect finalRect=startRect;
                  finalRect.setWidth(100);
                  showTrevwAnime->setStartValue(startRect);
                  showTrevwAnime->setEndValue(finalRect);

                  showTrevwAnime->start(QAbstractAnimation::DeleteWhenStopped);
                  

                  }
                  @[/quote]

                  Thanks, but...is this the reason?! I can't believe it! I think I should change the object to the Parent Object(DockWidget), and change the property "geometry" into another. I'll try the code later.
                  BTW: I'd like to know more about your code. Mine is just let the TreeView invisible. Why just destroy it when it stop will work? Shouldn't we change the size of one of the part of the dock?

                  1 Reply Last reply Reply Quote 0
                  • raven-worx
                    raven-worx Moderators last edited by

                    sure thats the reason... the animation can only work when there is a object which controls the animation. When the animation object is destroyed there is no animation.
                    The DeleteWhenStopped argument is necessary to avoid memory leaks, since you don't hold a reference anywhere to delete it once it is finished.

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply Reply Quote 0
                    • S
                      Saki last edited by

                      [quote author="raven-worx" date="1372400678"]sure thats the reason... the animation can only work when there is a object which controls the animation. When the animation object is destroyed there is no animation.
                      The DeleteWhenStopped argument is necessary to avoid memory leaks, since you don't hold a reference anywhere to delete it once it is finished.[/quote]

                      I'm so sorry that this didn't work. I think that we shouldn't just change the geometry of TreeView. We should change the width of Dock's child window instead.

                      1 Reply Last reply Reply Quote 0
                      • S
                        Saki last edited by

                        Well, no one knows anything about this?

                        1 Reply Last reply Reply Quote 0
                        • S
                          Saki last edited by

                          All Right, It seems that I have to solve this problem by myself. Thanks for everyone.

                          1 Reply Last reply Reply Quote 0
                          • A
                            alizadeh91 last edited by

                            Hi, For animating QSplitter you have to have a animation on a property of QSplitter not on property of its child widgets. so as the QSplitter has no property for sizes so you have to create that property by yourself and animate through it. (Try it to change splitter position without animation at first and then add animation on that property)

                            1 Reply Last reply Reply Quote 0
                            • S
                              Saki last edited by

                              [quote author="Mostafa Alizadeh" date="1374577477"]Hi, For animating QSplitter you have to have a animation on a property of QSplitter not on property of its child widgets. so as the QSplitter has no property for sizes so you have to create that property by yourself and animate through it. (Try it to change splitter position without animation at first and then add animation on that property)[/quote]

                              Thanks a million, and I solved it by using QTimeLine. This is not relate to the DeleteWhenStopped, right?

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post