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. How to create Fade in, Fade out effect in Qt
QtWS25 Last Chance

How to create Fade in, Fade out effect in Qt

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 5.2k 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.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by
    #1

    Need guidence in qt, how to create special effect where QPushButton fades out and taken over by
    QRadioButton in Qt one by one.
    Not sure which class can achieve this effect.

    @
    //Below is the grid with 3 buttons
    QGridLayout *gridLayout = new QGridLayout;
    QPushButton *b1 = new QPushButton("A");
    QPushButton *b2 = new QPushButton("B");
    QPushButton *b3 = new QPushButton("C");
    QPushButton *b4 = new QPushButton("D");
    QPushButton *b5 = new QPushButton("E");
    QPushButton *b6 = new QPushButton("F");

    // row 0
    gridLayout->addWidget(b1,0,0,1,1);
    gridLayout->addWidget(b2,0,1,1,1);
    gridLayout->addWidget(b3,0,2,1,1);

    // row 1
    gridLayout->addWidget(b4,1,0,1,1);

    // row 2 with 2 column span
    gridLayout->addWidget(b5,2,0,1,2);

    //row 3 with 3-column span
    gridLayout->addWidget(b6,3,0,1,3);

    //create a widget
    QWidget *w = new QWidget();
    w->setLayout(gridLayout);

    //Window Title
    w->setWindowTitle("Grid Layout 3 x4");
    //Display
    w->show();

    }

    @

    1 Reply Last reply
    0
    • E Offline
      E Offline
      euchkatzl
      wrote on last edited by
      #2

      Could you explain a bit more what you want to archive ?

      On Button Clicked the Button should disappear and at the same place there should then be a radio button ?

      1 Reply Last reply
      0
      • H Offline
        H Offline
        houmingc
        wrote on last edited by
        #3

        In QGridlayout, how to replace item A with item B

        1 Reply Last reply
        0
        • E Offline
          E Offline
          euchkatzl
          wrote on last edited by
          #4

          Not quit sure if this is what you expect. But i think you could simply use it for your approach.

          @class FadeOutButton : public QWidget
          {
          Q_OBJECT
          public:
          explicit FadeOutButton(QWidget *parent = 0);
          ~FadeOutButton();

          signals:

          private slots:
          void onButtonClicked();
          void onAnimationFinished();
          private :
          QPushButton* mButton;
          QRadioButton * mRadioButton;
          QGraphicsOpacityEffect* mEffect;
          };@

          @FadeOutButton::FadeOutButton(QWidget *parent) : QWidget(parent)
          {

          QGridLayout* layout = new QGridLayout(this);
          layout->setContentsMargins(0,0,0,0);
          
          mButton = new QPushButton("Button",this);
          mRadioButton = new QRadioButton(this);
          
          layout->addWidget(mButton,0,0,1,1);
          layout->addWidget(mRadioButton,0,0,1,1);
          
          mEffect = new QGraphicsOpacityEffect(mButton);
          mEffect->setOpacity(1.0);
          mButton->setGraphicsEffect(mEffect);
          
          mRadioButton->setVisible(false);
          connect(mButton,SIGNAL(clicked()),this,SLOT(onButtonClicked()));
          

          }

          FadeOutButton::~FadeOutButton()
          {

          }

          void FadeOutButton::onButtonClicked()
          {
          QPropertyAnimation* animation = new QPropertyAnimation(mEffect,"opacity");
          animation->setDuration(500);
          animation->setStartValue(1.0);
          animation->setEndValue(0.0);
          connect(animation,SIGNAL(finished()),this,SLOT(onAnimationFinished()));
          animation->start(QAbstractAnimation::DeleteWhenStopped);
          }

          void FadeOutButton::onAnimationFinished()
          {
          mButton->setVisible(false);
          mRadioButton->setVisible(true);

          }@

          1 Reply Last reply
          0
          • H Offline
            H Offline
            houmingc
            wrote on last edited by
            #5

            it work :> 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