Animate focused part of QDateTimeEdit

48 Views Asked by At

I need to animate QDateTimeEdit widget as follows;

When user focuses/edits year section, it should be animated using opacity property. ( like flickering, show and hide for every second ) Qt animation could only be used for widgets. But the part I'm trying to animate is "section", type of enum.

After some research, I've found a case as follows; aplying "QPropertyAnimation" for QRect.

https://stackoverflow.com/questions/43428627/applying-qpropertyanimation-to-qrect

In my case, I need to apply QPropertyAnimation for "QDateTimeEdit::Section" which is an enum ( https://doc.qt.io/qt-6/qdatetimeedit.html ). The goal is to blink/animate focused part (day) of the QDateTimeEdit widget

Could you please help me for the alternative ways of solution?

Alternatively, I've tried to catch focused part ( day, month or year ) while editing datetime;

this->setStyleSheet("QDateTimeEdit:focus { selection-background-color: red; selection-color: white; }")

For the way stated above, I need to set the stylesheet for different colors for every seconds. But, I could not find the way of transition between the start and end value( color) like in the animation ;

   QPushButton *button = new QPushButton(tr("Animated Button"), this);
    QPropertyAnimation *anim = new QPropertyAnimation(button, "opacity", this);
    anim->setDuration(1000);
    anim->setStartValue(1);
    anim->setEndValue(0)
    anim->start();
1

There are 1 best solutions below

2
On

Opacity is not a property of QPushButton. Animations only work on properties.