Results 1 to 10 of 10

Thread: initial position of a QSlider

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    620
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default initial position of a QSlider

    Hi to all,
    I'm building a little application where I need a QSlider. When I start the application I need the cursor to be positioned in the half of the slider but this doesn't happens.
    When I construct the window I set slider->setValue(5) //the range is 0...10, so 5 is the half
    but when I run the application the cursor is always positioned in the position 0.
    I don't know why.

    Regards,
    Franco

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: initial position of a QSlider

    Can you show the code how you are doing it ?

  3. #3
    Join Date
    Nov 2006
    Posts
    23
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: initial position of a QSlider

    Franco,

    Take a look at the QSlider class methods setSliderPosition ( int ) and setTracking ( bool ) ....

  4. #4
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    620
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: initial position of a QSlider

    Hi Thoosle,
    I gave a look here http://doc.trolltech.com/3.3/qslider.html about QSlider class, but there is no a setSliderPosition method
    May be I'm searching in the bad place?

    Regards,
    Franco

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: initial position of a QSlider

    I'm sure QSlider::setValue() works just fine. The problem must be elsewhere. Why don't you show the relevant code? Otherwise we can do nothing but guess.
    J-P Nurmi

  6. #6
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    620
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: initial position of a QSlider

    Hi,
    I post here the code where I construct the slider:

    Qt Code:
    1. QSlider *Window::createSlider()
    2. {
    3. QSlider *slider = new QSlider(0, 10, 1, 5 ); //5 = initial value
    4. slider->setSingleStep(1);
    5. slider->setPageStep(1);
    6. slider->setTickPosition(QSlidet::TicksRight);
    7.  
    8. return slider;
    9. }
    To copy to clipboard, switch view to plain text mode 

    And here I call the createSlider() routine:

    Qt Code:
    1. Window::Window()
    2. {
    3. cout << "Window::Window : window object created." << endl;
    4.  
    5. coinWidget = new CoinWidget; // the coin3d viewer
    6. volumeSlider = createSlider(); //here I construct the slider
    7. openAudioFileButton = createButton();
    8.  
    9. connect(volumeSlider, SIGNAL(valueChanged(int)), coinWidget, SLOT(setAudioTrackVolume(int)));
    10. connect(openAudioFileButton, SIGNAL(released()), coinWidget, SLOT(openAudioTrack()));
    11.  
    12. QHBoxLayout *mainLayout = new QHBoxLayout( this );
    13.  
    14. mainLayout->addWidget(coinWidget);
    15. mainLayout->addSpacing( 10 );
    16. mainLayout->addWidget(volumeSlider);
    17. mainLayout->addSpacing( 30 );
    18. mainLayout->addWidget(openAudioFileButton);
    19. mainLayout->addSpacing( 30 );
    20. setLayout(mainLayout);
    21. setWindowTitle(tr("Sound Test Environment"));
    22. }
    To copy to clipboard, switch view to plain text mode 

    That's all.
    I'm sure there is some errors in my code but I can't find it.
    I have an other question:
    Is possible to create a slider with smoth movement? I hope you can understand what I mean because my english's not perfect.

    Regards,
    Franco

  7. #7
    Join Date
    Nov 2006
    Posts
    23
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: initial position of a QSlider

    Franco,

    Sorry I wasn't paying attention to which version you're using. setSliderPosition method is in QT 4.

    This shouldn't work but have you tried setting the "value" after the QSlider has been instantiated? If for some strange reason the QSlider wasn't being initialized properly this could show??

  8. #8
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    620
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: initial position of a QSlider

    Thoosle yes I'm using QT 4.
    I followed your suggestion and now it works, but I don't understand why .
    Is possible to have a smooth movement of the cursor?

    Regards,
    Franco

  9. #9
    Join Date
    Nov 2006
    Posts
    23
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: initial position of a QSlider

    Franco,

    If you're using Qt4 then you need to look at the Qt4 docs, not Qt3. The QSlider constructor you show in your code is incorrect for Qt4. This is probably why it doesn't instantiate properly and why it works setting value after instantiation. QSlider has two constructors in Qt4 as follows:


    QSlider ( QWidget * parent = 0 )

    QSlider ( Qt::Orientation orientation, QWidget * parent = 0 )

    try this link http://doc.trolltech.com/4.3/qslider.html

  10. The following user says thank you to Thoosle for this useful post:

    franco.amato (24th September 2008)

  11. #10
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    620
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: initial position of a QSlider

    Quote Originally Posted by Thoosle View Post
    Franco,

    If you're using Qt4 then you need to look at the Qt4 docs, not Qt3. The QSlider constructor you show in your code is incorrect for Qt4. This is probably why it doesn't instantiate properly and why it works setting value after instantiation. QSlider has two constructors in Qt4 as follows:


    QSlider ( QWidget * parent = 0 )

    QSlider ( Qt::Orientation orientation, QWidget * parent = 0 )

    try this link http://doc.trolltech.com/4.3/qslider.html
    Thanks for the link.
    I didn't see the reference to qt 3 .
    Regards,
    Franco

Similar Threads

  1. toolbar initial position
    By baray98 in forum Qt Programming
    Replies: 7
    Last Post: 7th September 2007, 07:39
  2. Initial Dialog Position
    By nleverin in forum Newbie
    Replies: 1
    Last Post: 15th July 2007, 10:19

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.