Russian Qt Forum
Октябрь 02, 2024, 17:19 *
Добро пожаловать, Гость. Пожалуйста, войдите или зарегистрируйтесь.
Вам не пришло письмо с кодом активации?

Войти
 
  Начало   Форум  WIKI (Вики)FAQ Помощь Поиск Войти Регистрация  

Страниц: [1]   Вниз
  Печать  
Автор Тема: [РЕШЕНО] QPropertyAnimation и свойство "text" в QLabel  (Прочитано 3433 раз)
AlekseyK
Гость
« : Декабрь 07, 2010, 17:51 »

Не работает анимация QLabel  - смена (моргание) текста через определённые промежутки времени. Что я делаю неправильно?

Код следующий:
Код
C++ (Qt)
   m_p1stHeaderAnimation = new QPropertyAnimation(ui.m_labelHeader1, "text", this);
   m_p3rdHeaderAnimation = new QPropertyAnimation(ui.m_labelHeader3, "text", this);
...
m_p1stHeaderAnimation->setDuration(1300);
m_p1stHeaderAnimation->setKeyValueAt(0, "Flashing text 1");
m_p1stHeaderAnimation->setKeyValueAt(0.77, "");
m_p1stHeaderAnimation->setKeyValueAt(1, "");
m_p1stHeaderAnimation->setLoopCount(5);
 
/// Setups 3rd header animation
m_p3rdHeaderAnimation->setDuration(1300);
m_p3rdHeaderAnimation->setKeyValueAt(0, "Flashing text 3");
m_p3rdHeaderAnimation->setKeyValueAt(0.77, "");
m_p3rdHeaderAnimation->setKeyValueAt(1, "");
m_p3rdHeaderAnimation->setLoopCount(5);
...
// Start next header animation after previous
connect(m_p1stHeaderAnimation, SIGNAL(finished()), m_p3rdHeaderAnimation, SLOT(start()));
connect(m_p3rdHeaderAnimation, SIGNAL(finished()), m_p1stHeaderAnimation, SLOT(start()));
...
m_p1stHeaderAnimation->start();
 
m_labelHeader1 и m_labelHeader3 - объекты типа QLabel.

Даже привязал сигналы valueChanged к слотам repaint на всякий случай:
Код
C++ (Qt)
   disconnect(m_p1stHeaderAnimation, SIGNAL(valueChanged(QVariant)), ui.m_labelHeader1, SLOT(repaint()));
   disconnect(m_p3rdHeaderAnimation, SIGNAL(valueChanged(QVariant)), ui.m_labelHeader3, SLOT(repaint()));
 
но всё равно не работает. Почему?
« Последнее редактирование: Декабрь 07, 2010, 21:47 от AlekseyK » Записан
AlekseyK
Гость
« Ответ #1 : Декабрь 07, 2010, 20:00 »

QVariantAnimation:

Цитировать
Not all QVariant types are supported. Below is a list of currently supported QVariant types:

    * Int
    * Double
    * Float
    * QLine
    * QLineF
    * QPoint
    * QPointF
    * QSize
    * QSizeF
    * QRect
    * QRectF
    * QColor

If you need to interpolate other variant types, including custom types, you have to implement interpolation for these yourself.

Здесь наверное state machine нужна.
Записан
AlekseyK
Гость
« Ответ #2 : Декабрь 07, 2010, 21:43 »

Всё работает, нужно просто интерполятор для QString-a задать:

Код
C++ (Qt)
qRegisterAnimationInterpolator<QString>(StringInterpolator);
 
QVariant StringInterpolator(const QString &start, const QString &end, qreal progress)
{
    if(progress < 1.0)
       return start;
    else
        return end;
}

Так вообще можно делать анимацию для любых других типов.
Записан
AlekseyK
Гость
« Ответ #3 : Декабрь 07, 2010, 21:48 »

Но всё равно интересно для повышения образованности: как сделать тоже самое со state machine? Подмигивающий
Записан
Страниц: [1]   Вверх
  Печать  
 
Перейти в:  


Страница сгенерирована за 0.107 секунд. Запросов: 21.