Results 1 to 5 of 5

Thread: interesting problem : slider control..position passing to QListIterator object?

  1. #1
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default interesting problem : slider control..position passing to QListIterator object?

    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:assFileNameToVideoLabel(QStringList fileName,QStringListIterator *iterator,QSlider *slider)
    {
    timer = new QTimer;
    temp = fileName;
    localIterator = iterator;
    localSlider = slider;
    }


    void VideoDisplayer:layVideo()
    {
    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);

    }
    }

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: interesting problem : slider control..position passing to QListIterator object?

    Dispense with the iterator and keep the list and a simple index number (member variables) then:
    Qt Code:
    1. void VideoDisplayer::nextPicture() {
    2. if (m_index < list.size()-1)
    3. m_index++;
    4. showPicture();
    5. }
    6.  
    7. void VideoDisplayer::prevPicture() {
    8. if (m_index > 0)
    9. m_index--;
    10. showPicture();
    11. }
    12.  
    13. void sliderReleased() {
    14. int newIndex = localSlider->value();
    15. if (...) // bounds checks omitted
    16. m_index = newIndex;
    17. showPicture();
    18. }
    19.  
    20. void showPicture() {
    21. // bounds checks omitted
    22. videoLabel->setPixmap(QPixmap(list.at(m_index)));
    23. videoLabel->adjustSize();
    24. videoLabel->setScaledContents(true);
    25. localSlider->setValue(m_index);
    26. }
    To copy to clipboard, switch view to plain text mode 
    or some variation on the theme.

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

  3. #3
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default Re: interesting problem : slider control..position passing to QListIterator object?

    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".................................ple ase if you could tell me how to do it with the "iterator"!!

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: interesting problem : slider control..position passing to QListIterator object?

    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.

  5. The following user says thank you to ChrisW67 for this useful post:

    qt_user (3rd August 2010)

  6. #5
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default Re: interesting problem : slider control..position passing to QListIterator object?

    thanx a lot ...........

Similar Threads

  1. Passing an object from one form to the other.
    By cbarmpar in forum Qt Programming
    Replies: 10
    Last Post: 3rd September 2008, 14:12
  2. passing an object
    By mickey in forum General Programming
    Replies: 3
    Last Post: 16th January 2008, 10:27
  3. slider control and combo box in grid view
    By steg90 in forum Qt Programming
    Replies: 13
    Last Post: 21st November 2007, 10:45
  4. control not passing from dialog to code
    By quickNitin in forum Newbie
    Replies: 3
    Last Post: 28th June 2006, 11:35
  5. Passing Object to dll
    By ankurjain in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 09:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.