Results 1 to 9 of 9

Thread: QSpinbox

  1. #1
    Join Date
    Aug 2011
    Location
    Germany
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSpinbox

    Hi all.

    I need a Spinbox with 15 possible items. At the beginning the spinbox should have no item and is disabled. Then I scan for devices. As I find one device, I want to add this to the spinbox. This device can have number 1 .. 15. When I find another device with another number, I want to add this device to the spinbox.
    Furthermore I do not want to display only the number but additionally the devicename.

    Can I do this with QSpinBox? I have to use QT4.5.

  2. #2
    Join Date
    Jul 2011
    Posts
    16
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSpinbox

    I don't know about the Spin box but I would use the combo box in your case.

  3. #3
    Join Date
    Aug 2011
    Location
    Germany
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSpinbox

    I know it could be done with a Combobox, but it should be the Spinbox style.
    If QSpinbox can't do this, I have to create a widget unsing 1 QTextEdit and 2 QPushButtons and have to manage the slot of the buttons myself. But I hoped a QSpinBox can do this for me.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSpinbox

    You need to create your own spinbox subclass and implement textFromValue() and valueFromText() to convert numbers to whatever you want the textual representation of those numbers to be.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2011
    Location
    Germany
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSpinbox

    It's still the same Spinbox, but another problem:

    In my Subclass "MySpinBox" derived from QSpinBox I want to enable / disable the up- and down-buttons on my QSpinBox dynamically.
    So there is the getter
    Qt Code:
    1. StepEnabled QAbstractSpinBox::stepEnabled () const [virtual protected]
    To copy to clipboard, switch view to plain text mode 
    end the enum
    Qt Code:
    1. enum QAbstractSpinBox::StepEnabledFlag
    2.  
    3. QAbstractSpinBox::StepNone 0x00
    4. QAbstractSpinBox::StepUpEnabled 0x01
    5. QAbstractSpinBox::StepDownEnabled 0x02
    To copy to clipboard, switch view to plain text mode 
    But where is the setter? I just don't get it.
    Please help.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSpinbox

    There is no setter. stepEnabled() is a virtual method which you override and return the current state of buttons. If you want an external setter, implement one in your subclass and reimplement stepEnabled() to take the calls to this setter into account. You'll need a tri-state check -- enabled, disabled explicitly by the setter, disabled implicitly by the value of the spinbox (and the hidden state of disabled by both mechanisms at once).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Aug 2011
    Location
    Germany
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSpinbox

    But I don't know how to get access to the buttons.
    Could you plese give an example how to implement the setter? I think I have to know the member of QAbstractSpinBox, wich is of StepEnabled, and which is used by the class to do it's own enabling / disabling of the button.
    Please, so more help...

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSpinbox

    I don't understand your question. I think this is purely a matter of C++ skills. In doubt take a look at Qt source code how the method is implemented. This forum is not a place to teach you C++.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Aug 2011
    Location
    Germany
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSpinbox

    One more try to explain:
    I have implemented to stepEnabled() function.

    But I really don't know how to get access to the buttons. So I don't know what I really have to do in my setter-function.
    In QAbstractSpinBox there the enum (with the name) StepEnabled (first letter is capital letter where as the first letter of the function is a small letter). But this is just an enum, not a member-variable. So there is no access possible, either.

Similar Threads

  1. QSpinBox
    By ToddAtWSU in forum Qt Programming
    Replies: 10
    Last Post: 1st September 2012, 03:36
  2. disable QSpinBox
    By amitpatel22 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 2nd September 2011, 12:43
  3. QSpinbox
    By sonuani in forum Newbie
    Replies: 3
    Last Post: 21st March 2008, 10:36
  4. QSpinBox or QLabels
    By ToddAtWSU in forum Qt Programming
    Replies: 10
    Last Post: 27th November 2007, 20:10
  5. QSpinBox StyleSheet
    By The Storm in forum Qt Programming
    Replies: 2
    Last Post: 14th September 2007, 23:08

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.