Results 1 to 6 of 6

Thread: Access to QSpinbox Buttons

  1. #1
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Access to QSpinbox Buttons

    From what I can tell in the documentation the QSpinbox buttons are not derivatives of "QAbstractPushButtons" or anything handy; but that the QSpinBox actually handles the clicks and figures out whether they're within the button or text area?

    I say this because it contains no button objects from what I can tell, nor any accessors to said buttons.

    I've tried scrying the source code, but QSpinBox seems to inherit it's MouseEvents from QAbstractSpinBox and the source for those don't seem to imply there's even detection of where the click is happening.

    Any help on how to talk to these buttons and/or their events would be greatly appreciated. Also curious as to the why (if it's not obvious.)

    Thanks!

    EDIT: Actually, I just need how they talk. I assume the "Why" is that because QLineEdit will handle it's own clicks, so the spinbox only need to handle clicks that QLineEdit didn't take already; and thus only deals with the "buttons", but I still don't know what's going on with the buttons.

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

    Default Re: Access to QSpinbox Buttons

    ==========================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
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Access to QSpinbox Buttons

    I did end up reading that thread before (though had forgotten about it.) I had dismissed it as his solution seemed like a kluge at the time. Reviewing it again it looks better than it did.

    I'm still curious about the *signal* that's emitted. I was thinking this was the boolean that controlled the up vs. down.

    I could overwrite the mousePressEvent I guess, but then I'm re-implementing functionality rather than using the functionality that's already there. It seems like I should be able to tap into that boolean function they're using in the source.


    I'll check back, but for now I guess I'll use that code snippet.

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

    Default Re: Access to QSpinbox Buttons

    could overwrite the mousePressEvent I guess, but then I'm re-implementing functionality rather than using the functionality that's already there.
    Not quite:
    The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.
    ==========================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
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Access to QSpinbox Buttons

    What I meant was that they already have a function that detects which button was pressed. By writing a new one you're overwriting functionality (by capturing the mousepress that the side buttons want to detect) and re-implementing (as the function you are writing does the same thing as the one they've written.)


    That said, spinbox gave me more issues an I was already 90% of the way to writing my own over the top of theirs, I finally just made my own using actual pushbuttons and getting rid of all of the excess functionality of the QDoubleSpinBox that was getting in my way :s.


    EDIT: I should say that I understand where you're coming from, but I think the source code I looked at originally *was* mousePressEvent. Further, (predictably,) when I made my own mousePressEvent the spinbox acted much differently. Maybe I'm misunderstanding your point. Either way, this is just for discussion purposes now as I bypassed my need for a solution lol

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

    Default Re: Access to QSpinbox Buttons

    Ok, but what is your goal?
    If what you want/need is to catch the press event on the up/down buttons, and do something that QSpinBox doesn't do in addition to the original behaviour, then you can leave (call) the original functionality in your re-implementation and just add the part you need.
    when I made my own mousePressEvent the spinbox acted much differently.
    Differently but "good" or "bad" (in respect to your needs)?
    If good, ok, if bad, you are doing something wrong.
    But reimplementing doesn't have to mean you have to re implement the original implementation, you can use the original in yours, so I don't quite understand the problem you are seeing with the reimplementation of a method.
    ==========================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.

Similar Threads

  1. QSpinbox Button Access
    By mac_loo in forum Qt Programming
    Replies: 7
    Last Post: 17th May 2015, 23:22
  2. QSpinbox
    By Markus_AC in forum Qt Programming
    Replies: 8
    Last Post: 20th October 2011, 11:26
  3. QSpinBox setting buttons with using stylesheets
    By _franko_ in forum Qt Programming
    Replies: 2
    Last Post: 1st August 2011, 21:09
  4. QSpinBox buttons size
    By bcastalia in forum Qt Programming
    Replies: 0
    Last Post: 24th March 2011, 04:49
  5. Make QSpinBox up/down buttons disappear
    By stefanadelbert in forum Qt Programming
    Replies: 4
    Last Post: 14th April 2010, 23:40

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.