PDA

View Full Version : interesting problem : slider control..position passing to QListIterator object?



qt_user
3rd August 2010, 07:42
I wish to connect the slider with the iterator position(i.e. if the slider is pressed/released, the the image should be displayed accordingly)............ I can make a connect(localSlider,SIGNAL(sliderReleased()),..... ....) .....in the SLOt function I'll call localSlider->value() and accept the integeral value of the index of sldier value..............but how would I set the localIterator's position accordingly????
Below is a very simple to understand code snippet...


//CODE:

void VideoDisplayer::passFileNameToVideoLabel(QStringLi st fileName,QStringListIterator *iterator,QSlider *slider)
{
timer = new QTimer;
temp = fileName;
localIterator = iterator;
localSlider = slider;
}


void VideoDisplayer::playVideo()
{
connect(timer, SIGNAL(timeout()),this, SLOT(nextPicture()));
timer->start(1000);
}


void VideoDisplayer::nextPicture()
{
if(localIterator->hasNext())
{
videoLabel->setPixmap(QPixmap(localIterator->next()));
videoLabel->adjustSize();
videoLabel->setScaledContents(true);
//localSlider->setValue();
localSlider->setValue(temp.indexOf(localIterator->peekPrevious()));
//label->show();
}
else
{
disconnect(timer, SIGNAL(timeout()),this, SLOT(nextPicture()));

timer->stop();
localIterator->toFront();
localSlider->setValue(0);

}
}

ChrisW67
3rd August 2010, 08:28
Dispense with the iterator and keep the list and a simple index number (member variables) then:


void VideoDisplayer::nextPicture() {
if (m_index < list.size()-1)
m_index++;
showPicture();
}

void VideoDisplayer::prevPicture() {
if (m_index > 0)
m_index--;
showPicture();
}

void sliderReleased() {
int newIndex = localSlider->value();
if (...) // bounds checks omitted
m_index = newIndex;
showPicture();
}

void showPicture() {
// bounds checks omitted
videoLabel->setPixmap(QPixmap(list.at(m_index)));
videoLabel->adjustSize();
videoLabel->setScaledContents(true);
localSlider->setValue(m_index);
}
or some variation on the theme.

Edit: Use [code] tags around your code, it is the # on the editor tool bar.

qt_user
3rd August 2010, 08:37
Thanx but I don't want to dispense with the "iterator" as it is being used and passed by many functions and classes already.............I am sure there must be a way to do it with the "iterator".................................please if you could tell me how to do it with the "iterator"!!

ChrisW67
3rd August 2010, 09:19
OK. Your choice. Since the Java style list iterator interface has no method to set the current item by index you have no choice but to toFirst() and then next() "n+1" times. The STL-style iterator could do this a little more easily with the "i += n" notation.

qt_user
3rd August 2010, 12:30
thanx a lot ...........