0

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();
TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

0

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

mzimmers
  • 857
  • 7
  • 17
  • I've just written QPushButton as an example of animation. The way I am looking for is animation of QDateTimeEdit section part. ( dd/mm/yyyy). Day, month or year part refer Section of QDateTimeEdit, which is not a widget. So, is there any alternative way for the animation section (day part) like other widgets ? – developer_ Feb 27 '23 at 04:54
  • I don't think so. As you point out, sections are enums, not properties. One approach would be to write a custom button class (probably based on Rectangle) that supports multiple text objects (one for hours, one for minutes, one for seconds), and apply your animation to the desired text object. – mzimmers Feb 27 '23 at 14:25