Results 1 to 8 of 8

Thread: QSpinbox Button Access

  1. #1
    Join Date
    Feb 2011
    Location
    Austria
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QSpinbox Button Access

    Hi,

    I know this has been discussed several times here but I could not find any hint how to solve it actually. I would like to catch the mousepress event of a spin box in order to be able to reconfigure the box settings before the value actually changes. Background: my spinbox can support different ranges with different step sizes. So if one presses e.g. the up button I have to check before the actual value change whether a new range is to be entered or not (a new range would mean a new step size). For this reason I need to know whether up or down was pressed. Looking into the Qt code I can see that this decision is handled via internal hover states.

    Is there any way to either get access to this hover state or to find out about the currently pressed button ?

    Any hint appreciated.

    cheers

    m.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QSpinbox Button Access

    I would like to catch the mousepress event of a spin box in order to be able to reconfigure the box settings before the value actually changes.
    You can either subclass, or use an event filter.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2011
    Location
    Austria
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSpinbox Button Access

    Well, that doesn't solve my problem. Of course I can subclass and catch the event but I don't know which button was pressed. I don't see a way to find out whether up or down button was pressed!

    m.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QSpinbox Button Access

    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Feb 2011
    Location
    Austria
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSpinbox Button Access

    :-) I guess there's still some misunderstanding ... I need access to the up/down buttons of the spinbox. I have subclassed QSpinbox already but I have no way to identify whether up or down was pressed when in mousepressevent !

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QSpinbox Button Access

    you can tell by the value.
    If the incoming value is larger than it was the up arrow, otherwise the down.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Feb 2011
    Location
    Austria
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSpinbox Button Access

    Actually I can't as at the time I enter mousepressevent the current value has not changed yet. Step up or down is triggered in exactely this function.
    I'm looking for a way to identify the pressed button ...


    Added after 28 minutes:


    Ok, finally found out how it work's !! (similar to QSpinBox but quite tricky to find out)

    Subclass QSpinBox and overwrite QSpinBox::mousePressEvent.
    Get the SubClass rectangle of the corresponding SpinBox arrow of the complex control first, then check whether your mouse pointer position is inside the rectangle, that's it.

    See the code snippet:

    QStyleOptionSpinBox opt;
    this->initStyleOption(&opt);
    QRect rect = this->style()->subControlRect(QStyle::CC_SpinBox,&opt,QStyle::SC _SpinBoxUp);
    if(rect.contains(event->pos()))
    qDebug() << "UP";
    else
    qDebug() << "DOWN";

    Cheers

    M.
    Last edited by mac_loo; 22nd February 2011 at 23:03.

  8. The following user says thank you to mac_loo for this useful post:

    R-Type (13th February 2015)

  9. #8
    Join Date
    Mar 2015
    Posts
    5
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Thumbs up Re: QSpinbox Button Access

    mac_loo (Y) Thank you

Similar Threads

  1. Can I get button Event on QSpinBox
    By sosanjay in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2010, 10:27
  2. Replies: 6
    Last Post: 22nd September 2008, 12:53
  3. Hardware button access in qtopia
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 27th August 2008, 23:16
  4. QSpinbox up and down button notification
    By seldeepchan in forum Qt Programming
    Replies: 1
    Last Post: 6th March 2008, 11:28
  5. QSpinBox button size
    By dvmorris in forum Qt Programming
    Replies: 1
    Last Post: 13th August 2007, 09:20

Tags for this Thread

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.