Results 1 to 4 of 4

Thread: subclass QSlider to go to a value on one click

  1. #1
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default subclass QSlider to go to a value on one click

    Hi everybody

    I'm writing a video player right now and I need a slider like in media player classic. I've was frustrated when I found that Qt does not have a way to go to the certain value on click. So I've tried to do it by subclassing QSlider like this:
    Qt Code:
    1. void QProgressSlider::mouseReleaseEvent(QMouseEvent* event)
    2. {
    3. event->ignore();
    4. double k = ((double)event->x())/((double)width());
    5. int a = k*(maximum());
    6. setValue(a);
    7. }
    To copy to clipboard, switch view to plain text mode 
    This is close but some times the handle misses the cursor. I've also tried to use
    int QSliderPrivate:: pixelPosToRangeValue(int pos) function but the results are the same.

    Any suggestions ?
    C++ & AMD forever

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

    Default Re: subclass QSlider to go to a value on one click

    One can do it easily with good old [WIKI]proxy style[/WIKI]:
    Qt Code:
    1. int MyStyle::styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const
    2. {
    3. if (hint == SH_Slider_AbsoluteSetButtons)
    4. return Qt::LeftButton; // or "Qt::LeftButton | Qt::RightButton"
    5. return ProxyStyle::styleHint(hint, option, widget, returnData);
    6. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 26th May 2008 at 17:00.
    J-P Nurmi

  3. #3
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: subclass QSlider to go to a value on one click

    Any details ?
    C++ & AMD forever

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

    Default Re: subclass QSlider to go to a value on one click

    READ through the link I gave.
    J-P Nurmi

Similar Threads

  1. Double Click Capturing
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2011, 14:12
  2. QGraphicsScene Click / Double Click
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 04:32

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.