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, partially works.
Forum Updated to NodeBB v4.3 + New Features

QPropertyAnimation, partially works.

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 437 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.
  • lincolnL Offline
    lincolnL Offline
    lincoln
    wrote on last edited by
    #1

    Hi guys I have a query about QPropertyAnimation, I have a form with a QTableView where I show data, and then below in a GroupBox some controls, which together are the details, I made an animation to show that GroupBox, when I clicked on a button , it is shown and hidden well, but when you continue clicking it no longer shows anything, any suggestion would be appreciated, greetings.
    I leave my code.

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QSqlDatabase>
    #include <QSqlTableModel>
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
      Q_OBJECT
    
    public:
      MainWindow(QWidget *parent = nullptr);
      ~MainWindow();
    
    private slots:
      void on_btnMostrar_clicked();
    
    private:
      Ui::MainWindow *ui;
      QSqlDatabase mDb;
      QSqlTableModel *model;
      int _height=0;
      int endValue=0;
      bool showDetails=false;
    
    };
    #endif // MAINWINDOW_H
    
    
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QSqlError>
    #include <QMessageBox>
    #include <QtDebug>
    #include <QPropertyAnimation>
    #include <QDebug>
    
    MainWindow::MainWindow(QWidget *parent)
      : QMainWindow(parent), ui(new Ui::MainWindow)
    {
      ui->setupUi(this);
      qInfo()<<mDb.drivers();
      mDb=QSqlDatabase::addDatabase("QPSQL");
      if(!mDb.isDriverAvailable("QPSQL")){
          QMessageBox::critical(this,qApp->applicationName(),mDb.lastError().text());
          return;
        }
      mDb.setPort(5432);
      mDb.setHostName("localhost");
      mDb.setDatabaseName("covid");
      mDb.setUserName("postgres");
      mDb.setPassword("password");
      if(!mDb.open()){
          QMessageBox::critical(this,qApp->applicationName(), mDb.lastError().text());
          return;
        }
      model=new QSqlTableModel(this);
      model->setTable("datos");
      model->select();
      
      ui->tableView->setModel(model);
      ui->gbDatos->setVisible(false);
    //  ui->btnMostrar->setCheckable(true);
    
    }
    
    MainWindow::~MainWindow()
    {
      delete ui;
    }
    void MainWindow::on_btnMostrar_clicked()
    {
      if(showDetails==true)
        _height=this->height();
      else
        _height=this->height()-ui->gbDatos->height();
    
      if(_height==293){
          endValue=this->height();
          showDetails=true;
          ui->gbDatos->setVisible(true);
        }else{
          endValue=293;
          showDetails=false;
          ui->gbDatos->setVisible(false);
        }
    
      QPropertyAnimation *animate=new QPropertyAnimation(this,"minimumHeight");
      animate->setDuration(1000);
      animate->setStartValue(_height);
      animate->setEndValue(endValue);
      animate->setEasingCurve(QEasingCurve::OutQuad);
      animate->start();
    }
    

    a32f0005-4059-4de7-93d7-d9b69e82cf21-image.png

    90ab815f-95ae-48bf-ba4e-3d802b043593-image.png

    Solitary wolf

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

      You can use for example the size hint to get the estimated final size of your widget.

      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
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        293 looks like a magic number that is going to get you in trouble.

        You should not rely on that kind of value for your animations.

        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
        1
        • lincolnL Offline
          lincolnL Offline
          lincoln
          wrote on last edited by
          #3

          @SGaist said in QPropertyAnimation, partially works.:

          293 looks like a magic number that is going to get you in trouble.
          You should not rely on that kind of value for your animations.

          And then what should I use, would be the question.

          Solitary wolf

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

            You can use for example the size hint to get the estimated final size of your widget.

            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
            1
            • lincolnL Offline
              lincolnL Offline
              lincoln
              wrote on last edited by
              #5

              great, fix my little problem, thanks.

              Solitary wolf

              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