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. Hover ToolButton GIF Not Moving
Forum Updated to NodeBB v4.3 + New Features

Hover ToolButton GIF Not Moving

Scheduled Pinned Locked Moved General and Desktop
15 Posts 2 Posters 5.3k 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.
  • raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by
    #4

    no you misunderstood me.
    I was talking about something like this:
    @
    QMovie *movie = new QMovie;
    movie->setFileName("../GIF/animated-picture.gif");
    animatedButton->setIcon(movie->currentPixmap());
    connect(movie, SIGNAL(frameChanged()), this, SLOT(onFrameChanged()));

    ...

    //SLOT
    void onFrameChanged()
    {
    animatedButton->setIcon( movie->currentPixmap() );
    }
    @

    --- 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
    0
    • W Offline
      W Offline
      wallacesoh
      wrote on last edited by
      #5

      Thanks raven-worx. I tried your codes and there is no display on the tool button. May I know why do we need to declare twice of the following?

      @animatedButton->setIcon(movie->currentPixmap());@

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #6

        sorry... i forgot to call start() on the QMovie.

        [quote author="wallacesoh" date="1381395886"]May I know why do we need to declare twice of the following?

        @animatedButton->setIcon(movie->currentPixmap());@[/quote]

        you actually don't need it, i just did it to have an initial icon set on the tool button. But once the QMovie emits frameChanged() signal a icon will be set anyway.

        [quote author="wallacesoh" date="1381395886"]I tried your codes and there is no display on the tool button.[/quote]

        Please make sure that the path to file is valid.
        e.g. use QFile::exists(...) for a quick check.

        --- 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
        0
        • W Offline
          W Offline
          wallacesoh
          wrote on last edited by
          #7

          When I called start() on the QMovie, the GIF appears. However it's not moving. It's a working GIF.

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #8

            hmm... what does QMovie::isValid() return?

            --- 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
            0
            • W Offline
              W Offline
              wallacesoh
              wrote on last edited by
              #9

              It is valid. The slot, onFrameChanged() is probably not being called.

              1 Reply Last reply
              0
              • raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #10

                [quote author="wallacesoh" date="1381399626"]It is valid. The slot, onFrameChanged() is probably not being called. [/quote]

                -what does the connect statement return? If false whats the output in the console?-

                damn it ... signal signature was wrong:
                @
                connect(movie, SIGNAL(frameChanged(int)), this, SLOT(onFrameChanged()));
                @

                --- 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
                0
                • W Offline
                  W Offline
                  wallacesoh
                  wrote on last edited by
                  #11

                  Great! Thanks raven-worx. :) It worked! I guess the missing int is the reason why the SLOT is not being called.

                  1 Reply Last reply
                  0
                  • W Offline
                    W Offline
                    wallacesoh
                    wrote on last edited by
                    #12

                    Sorry. I would like to ask another question. If I were to hover the tool button and display this GIF. Would it be the same?

                    My current codes are:
                    @animatedButton->setStyleSheet("QToolButton:hover { background-image: url(../GIF/animated-picture.gif"); }");@

                    But it won't animate. Is there a way to connect the signal and slot to setStyleSheet?

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      wallacesoh
                      wrote on last edited by
                      #13

                      I have tried mouse events:

                      @movie->setFileName("../GIF/animated-picture.gif");
                      movie->start();
                      animatedButton->setIcon(movie->currentPixmap());
                      connect(movie, SIGNAL(frameChanged(int)), this, SLOT(onFrameChanged()));

                      void ToolBarPalettes::enterEvent(QEvent *event)
                      {
                      animatedButton->setIcon(movie->currentPixmap());
                      }

                      void ToolBarPalettes::leaveEvent(QEvent *event)
                      {
                      animatedButton->setIcon(QPixmap("../IMG/still-picture.png"));
                      }@

                      I understand that onFrameChanged() is not called. Therefore, the animation doesn't works. Is it possible to change the connect statement to cater to mouse enter events?

                      1 Reply Last reply
                      0
                      • raven-worxR Offline
                        raven-worxR Offline
                        raven-worx
                        Moderators
                        wrote on last edited by
                        #14

                        define your custom ToolButton class like this:
                        @
                        class MyAnimatedToolButton : public QToolButton
                        {
                        Q_OBJECT
                        Q_PROPERT(QString animatedIconPath READ animatedIconPath WRITE setAnimatedIconPath DESIGNABLE true )

                        public:
                        MyAnimatedToolButton(QWidget* parent = 0) : QToolButton(parent)
                        {
                        connect(&movie, SIGNAL(frameChanged()), this, SLOT(onFrameChanged()));
                        }

                         QString animatedIconPath() const
                         {
                              return movie.filePath();
                         }
                        
                         void setAniamtedIconPath(const QString & path)
                         {
                               movie.setFilePath(path);
                               if( path.isEmpty() )
                                    movie.stop();
                               else
                                     movie.start();
                         }
                        

                        protected slots:
                        void onFrameChanged()
                        {
                        this->setIcon( movie.currentPixmap() );
                        }

                        protected:
                        QMovie movie;
                        }
                        @

                        Then you can do this in your stylesheet:
                        @
                        MyAnimatedToolButton
                        {
                        qproperty-animatedIconPath: "../GIF/animated-picture.gif";
                        }

                        MyAnimatedToolButton:hover
                        {
                        qproperty-animatedIconPath: "";
                        qproperty-icon: url(../IMG/stillpicture.png");
                        }
                        @

                        This should give you an idea.

                        Or go with the event handler approach like you tried. But then take care of stopping the QMovie at the appropriate point:
                        @
                        void ToolBarPalettes::enterEvent(QEvent *event)
                        {
                        movie->start();
                        }

                        void ToolBarPalettes::leaveEvent(QEvent *event)
                        {
                        movie->stop();
                        animatedButton->setIcon(QPixmap("../IMG/still-picture.png"));
                        }
                        @

                        --- 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
                        0
                        • W Offline
                          W Offline
                          wallacesoh
                          wrote on last edited by
                          #15

                          Thanks raven-worx! For now, I am trying out the event handler method which works perfectly. I did not include @movie->stop();@ which stops the animation upon start of the application.

                          But I shall try your proposed stylesheet method as an alternative solution.

                          Thanks alot! :)

                          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