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. QPropertyAnimation can't used to Qtabwidget
Forum Updated to NodeBB v4.3 + New Features

QPropertyAnimation can't used to Qtabwidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.9k Views
  • 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.
  • hezfH Offline
    hezfH Offline
    hezf
    wrote on last edited by
    #1

    I want to hide the Qtabwidget
    So I used QPropertyAnimation to make Qtabwidget's width is 0 in 400ms
    but the tabwidget will rebound
    the tabwidget's sizepolicy is expanding
    other widget is okay,like Qframe,buton.....
    I don't know how to do that

    //frame_2 has the tabwidget
        QPropertyAnimation *animation= new QPropertyAnimation(ui->frame_2,"geometry");
        animation->setDuration(400);
        animation->setStartValue(ui->frame_2->geometry());
        if(expanded){
            animation->setEndValue(QRect(0,0, 0, ui->frame_2->height()));
        }
        else {
            animation->setEndValue(QRect(0,0, 500, ui->frame_2->height()));
        }
    
    D 1 Reply Last reply
    0
    • hezfH hezf

      I want to hide the Qtabwidget
      So I used QPropertyAnimation to make Qtabwidget's width is 0 in 400ms
      but the tabwidget will rebound
      the tabwidget's sizepolicy is expanding
      other widget is okay,like Qframe,buton.....
      I don't know how to do that

      //frame_2 has the tabwidget
          QPropertyAnimation *animation= new QPropertyAnimation(ui->frame_2,"geometry");
          animation->setDuration(400);
          animation->setStartValue(ui->frame_2->geometry());
          if(expanded){
              animation->setEndValue(QRect(0,0, 0, ui->frame_2->height()));
          }
          else {
              animation->setEndValue(QRect(0,0, 500, ui->frame_2->height()));
          }
      
      D Offline
      D Offline
      Devopia53
      wrote on last edited by
      #2

      @hezf
      Hi,
      Do you have a layout for the QTabWidget?
      If you have a layout, the QTabWidget will re-arranged by layout.

      hezfH 1 Reply Last reply
      0
      • D Devopia53

        @hezf
        Hi,
        Do you have a layout for the QTabWidget?
        If you have a layout, the QTabWidget will re-arranged by layout.

        hezfH Offline
        hezfH Offline
        hezf
        wrote on last edited by
        #3

        @Devopia53
        yes,I used layout
        but why others is okay?like qpushbutton...
        and if I don't use a layout ,what Can I do for layout ?
        Thank you for your answer.

        D 1 Reply Last reply
        0
        • hezfH hezf

          @Devopia53
          yes,I used layout
          but why others is okay?like qpushbutton...
          and if I don't use a layout ,what Can I do for layout ?
          Thank you for your answer.

          D Offline
          D Offline
          Devopia53
          wrote on last edited by Devopia53
          #4

          @hezf
          If parent widget changed(like size), other widgets will re-arranged also.
          You should remove layout of QFrame and then use hide()/show() for QFrame.

          Ex)

          [...] 
          // set up animation, frame has the QTabWidget
              animation= new QPropertyAnimation(ui->frame, "geometry");
              animation->setDuration(400);
              animation->setStartValue(ui->frame->geometry());
              animation->setEndValue(QRect(ui->frame->x(), ui->frame->y(), 0, ui->frame->height()));
              connect(animation, &QPropertyAnimation::finished,
                      [&]{ if (animation->direction() == QPropertyAnimation::Forward) {
                      ui->frame->hide();
                      animation->setDirection(QPropertyAnimation::Backward);
                  }
                  else
                      animation->setDirection(QPropertyAnimation::Forward);
              });
          
          [...]
          
          // start animation
              if (animation->direction() == QPropertyAnimation::Backward)
                  ui->frame->show();
              animation->start();
          
          
          hezfH 2 Replies Last reply
          0
          • D Devopia53

            @hezf
            If parent widget changed(like size), other widgets will re-arranged also.
            You should remove layout of QFrame and then use hide()/show() for QFrame.

            Ex)

            [...] 
            // set up animation, frame has the QTabWidget
                animation= new QPropertyAnimation(ui->frame, "geometry");
                animation->setDuration(400);
                animation->setStartValue(ui->frame->geometry());
                animation->setEndValue(QRect(ui->frame->x(), ui->frame->y(), 0, ui->frame->height()));
                connect(animation, &QPropertyAnimation::finished,
                        [&]{ if (animation->direction() == QPropertyAnimation::Forward) {
                        ui->frame->hide();
                        animation->setDirection(QPropertyAnimation::Backward);
                    }
                    else
                        animation->setDirection(QPropertyAnimation::Forward);
                });
            
            [...]
            
            // start animation
                if (animation->direction() == QPropertyAnimation::Backward)
                    ui->frame->show();
                animation->start();
            
            
            hezfH Offline
            hezfH Offline
            hezf
            wrote on last edited by
            #5

            @Devopia53
            thank you,I will try it.

            1 Reply Last reply
            0
            • D Devopia53

              @hezf
              If parent widget changed(like size), other widgets will re-arranged also.
              You should remove layout of QFrame and then use hide()/show() for QFrame.

              Ex)

              [...] 
              // set up animation, frame has the QTabWidget
                  animation= new QPropertyAnimation(ui->frame, "geometry");
                  animation->setDuration(400);
                  animation->setStartValue(ui->frame->geometry());
                  animation->setEndValue(QRect(ui->frame->x(), ui->frame->y(), 0, ui->frame->height()));
                  connect(animation, &QPropertyAnimation::finished,
                          [&]{ if (animation->direction() == QPropertyAnimation::Forward) {
                          ui->frame->hide();
                          animation->setDirection(QPropertyAnimation::Backward);
                      }
                      else
                          animation->setDirection(QPropertyAnimation::Forward);
                  });
              
              [...]
              
              // start animation
                  if (animation->direction() == QPropertyAnimation::Backward)
                      ui->frame->show();
                  animation->start();
              
              
              hezfH Offline
              hezfH Offline
              hezf
              wrote on last edited by
              #6

              @Devopia53
              Hi,
              Can you send me the project?
              hezf@boltit.cn

              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