2014-11-04 1 views

답변

2

나는 QPropertyAnimation을 사용하여 작업을 제안합니다. 값을 변경하려는 시작 값, 종료 값 및 곡선을 설정하십시오.

QPropertyAnimation *animation = new QPropertyAnimation(slider,"sliderPosition"); 
//set the duration (how long the animation should run - will change value faster when shorter) 
animation->setDuration(1000); 
//set the start value - in this case check if value in range of the slider 
animation->setStartValue(slider->minimum()); 
//same as start value 
animation->setEndValue(slider->maximum()); 
//easingCurve defines if it goes straight or bouncing n stuff 
animation->setEasingCurve(QEasingCurve::OutCubic); 

// as coyote mentioned, you can loop the animation as well (credit him as well ;)) 
// -1 defines to run forever 
animation->setLoopCount(loopCount) 

animation->start(); 
+1

루프 수를 무기한으로 변경하여 – coyotte508

+0

덕분에 @ coyotte508이 (가) 이미 해당 기능을 잊어 버렸을 수도 있습니다. – Zaiborg

2

이것은 타이머의 슬라이더 위치를 업데이트하는 문제 일뿐입니다. 타이머를 만들고 업데이트 할 때마다 QSlider::setValue으로 전화하십시오.

값이 최대 값이면 다시 최소값으로 설정하고 계속하십시오.

QSlider* pSlider = new QSlider; 

QButton * pButton = new QButton("Go"); 

QTimer* pTimer = nullptr; // C++ 11 nullptr 

// On button click, start a timer 
connect(pButton, &QButton::clicked(), [=](){ 

    // exit if already running 
    if(pTimer) 
     return;  

    pTimer = new QTimer; 
    connect(pTimer, &QTimer::timeout, [=](){ 

     if(pSlider->value()+1 > pSlider->maximum()) 
      pSlider->setValue(pSlider->minimum()); 
     else 
      pSlider->setValue(++pSlider->value());  
    }); 
    pTimer->start(1000); // update every second 
}); 
1

QTimer을 사용할 수 있습니다. 최소 예 :

QSlider *sl = new QSlider; 
QTimer *ttt = new QTimer; 
sl->setValue(0); 

connect(ttt,&QTimer::timeout,[=]() { 
    sl->setValue(sl->value() + 5); 
}); 
sl->show(); 
ttt->start(500); 

내가하고 new syntax of signals and slots (.pro 파일에 CONFIG += c++11) 여기 C++11 사용하지만, 당신이 원한다면 물론 당신은 오래된 구문을 사용할 수 있습니다.

1

필자의 지식에 대한 표준 접근 방식은 없습니다.

타이머는 다른 답변으로 제공되지만 animation framework을 사용하고 애니메이션 기간을 조정하여 속도를 조정할 수도 있습니다.

loopcount를 애니메이션 실행 횟수 (예 : 1000000)로 설정하면 장시간 실행 할 수 있습니다.

관련 문제