Results 1 to 3 of 3

Thread: QwtPlotTextLabel and animations

  1. #1
    Join Date
    Oct 2013
    Location
    Quebec
    Posts
    31
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default QwtPlotTextLabel and animations

    Hi,

    I would like to implement a fade in/fade out animation on a QwtPlotTextLabel.
    Since QwtPlotTextLabel is not a QObject, I haven't figured yet how to make this possible.

    Here is a screenshot of what I have now (message in middle on the graph, still need to do the fade out animation)

    Maybe i'll have to use a QLabel or a QWidget instead of QwtPlotTextLabel? If so, I'm not sure how to place a widget on top of the QwtPlot that is transparent..
    Thanks in advance!!

  2. #2
    Join Date
    Oct 2013
    Location
    Quebec
    Posts
    31
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwtPlotTextLabel and animations

    So far i'm using a QLabel instead of QwtPlotTextLabel.
    It's working with this code, just have to figure how to put the QLabel on top of the QwtPlot now

    #include "faderqlabel.h"

    #include <QGraphicsOpacityEffect>
    #include <QPropertyAnimation>
    #include <QTimer>


    FaderQLabel::FaderQLabel(QWidget *parent, int timeFadeIn, int timeFadeOut, int fadeOutAfter) : QLabel(parent) {


    this->timeFadeIn = timeFadeIn;
    this->timeFadeOut = timeFadeOut;

    QTimer *fadeOutTimer = new QTimer(this);
    connect(fadeOutTimer, SIGNAL(timeout()), this, SLOT(fadeOut()));
    fadeOutTimer->start(fadeOutAfter);

    }


    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// SLOT FADE_OUT
    void FaderQLabel::fadeOut() {

    QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(this);
    this->setGraphicsEffect(effect);
    QPropertyAnimation *anim = new QPropertyAnimation(this);
    anim->setPropertyName("opacity");
    anim->setTargetObject(effect);
    anim->setDuration(timeFadeOut);
    anim->setStartValue(1.0);
    anim->setEndValue(0.0);
    anim->setEasingCurve(QEasingCurve::OutQuad);
    anim->start(QAbstractAnimation:eleteWhenStopped);
    }

  3. #3
    Join Date
    Oct 2013
    Location
    Quebec
    Posts
    31
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwtPlotTextLabel and animations

    Just to plot my solution.

    I made a QWidget containing a QGridLayout
    the QGridLayout contain a QLabel and a QwtPlot Item.
    that way, I can put the QLabel on top of the QwtPlotItem and use the animation effect


    Added after 1 16 minutes:


    Turn out QwtPlot canvas use a QWidget.. I put my QLabel directly there for less code


    ///////////////////////////////////////////////////////////////////////////////

    QLabel *labelMsg = new QLabel(this);
    labelMsg->setText("TEST MSG ICI");
    labelMsg->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    labelMsg->setStyleSheet("background-color : rgba(1,1,1,128);");


    QWidget *ptnWidget = this->canvas();

    QGridLayout *gridLayout;
    gridLayout = new QGridLayout(this);
    gridLayout->addWidget(labelMsg, 0, 0, 1, 1);

    ptnWidget->setLayout(gridLayout);


    QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(labelMsg);
    labelMsg->setGraphicsEffect(effect);
    QPropertyAnimation *anim = new QPropertyAnimation(labelMsg);
    anim->setPropertyName("opacity");
    anim->setTargetObject(effect);
    anim->setDuration(3000);
    anim->setStartValue(1.0);
    anim->setEndValue(0.0);
    anim->setEasingCurve(QEasingCurve::OutQuad);
    anim->start(QAbstractAnimation:eleteWhenStopped);

    /////////////////////////////////////////////////////////////////////////////
    Last edited by Maximus2; 9th January 2014 at 02:44.

Similar Threads

  1. Replies: 9
    Last Post: 14th June 2013, 09:18
  2. Sequential animations on each listitem
    By rama.kesi in forum Qt Quick
    Replies: 3
    Last Post: 12th October 2012, 04:36
  3. Animations
    By hema in forum Newbie
    Replies: 2
    Last Post: 11th July 2011, 13:05
  4. Animations
    By hema in forum The GraphicsView Framework
    Replies: 0
    Last Post: 8th July 2011, 07:54
  5. How to remove animations?
    By mirelon in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2010, 10:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.