Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. How to animate a QSplitter?
Forum Updated to NodeBB v4.3 + New Features

How to animate a QSplitter?

Scheduled Pinned Locked Moved Unsolved QtWebEngine
2 Posts 2 Posters 433 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.
  • K Offline
    K Offline
    Kattia
    wrote on last edited by
    #1

    Given the following example built-in Qt Designer:

    enter image description here

    The GUI is started with the space occupied by frame hidden:

        QList<int> list = { 0, 400 };
        ui.splitter->setSizes(list);
        ui.frame->setWindowOpacity(0);
    

    How can I animate the frame while bringing her occupied space back?

    I tried animating it as:


    // splitteranimation.h
    
    void SplitterAnimation(QWidget* widget)
    {
        int ani_speed = 1000;
    
        QPropertyAnimation* geo_ani = new QPropertyAnimation(widget, "geometry");
        geo_ani->setDuration(ani_speed);
        geo_ani->setStartValue(widget->rect());
    
        QRect end = QRect(widget->rect().x(), widget->rect().y(), widget->rect().width() + 200, widget->rect().height());
        geo_ani->setEndValue(end);
    
    
    
        QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect();
        widget->setGraphicsEffect(eff);
        QPropertyAnimation *op_eff = new QPropertyAnimation(eff, "opacity");
        op_eff->setDuration(ani_speed);
        op_eff->setStartValue(0);
        op_eff->setEndValue(1);
    
    
    
        auto animgroup = new QParallelAnimationGroup;
        animgroup->addAnimation(geo_ani);
        animgroup->addAnimation(op_eff);
        animgroup->start(QAbstractAnimation::DeleteWhenStopped);
    }
    

    #include "splitteranimation.h"
    
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
    {
        ui.setupUi(this);
    
        QList<int> list = { 0, 400 };
        ui.splitter->setSizes(list);
        ui.frame->setWindowOpacity(0);
    
        QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_F2), this);
        connect(shortcut, &QShortcut::activated, [=]
        {
            qDebug() << "shortcut!";
    	    SplitterAnimation(ui.frame);
    
        });
    
        shortcut = new QShortcut(QKeySequence(Qt::Key_F3), this);
        connect(shortcut, &QShortcut::activated, [this]
        {
            qDebug() << "shortcut!";
    	    SplitterAnimation(ui.splitter);
        });
    }
    

    When I call the geometry animation in the frame (F2), the frame get resized but the space occupied by it continue 'hidden', the splitter areas didn't get resized:

    enter image description here

    When i call the animation directly in the splitter (F3), the frame didn't get resized/ visible.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      From the top of my head, I would rather animate the handle than the widget that is in the splitter.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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