Results 1 to 4 of 4

Thread: QAbstractSpinBox subclassing

  1. #1
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QAbstractSpinBox subclassing

    Hi,

    I want to make my personal speedbox for set a variable type like this:

    X 0000, Y 0000, Z 0000, A 000, B 000, C 000

    where X,Y,Z can be change from -9999 to 9999 and A,B,C can be change from -270 to 270.

    I have write this code

    miospinbox.h
    Qt Code:
    1. #include <QWidget>
    2. #include <QAbstractSpinBox>
    3. #include <QLineEdit>
    4. #include <QValidator>
    5.  
    6. class miospinbox : public QAbstractSpinBox
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. miospinbox();
    12.  
    13. };
    To copy to clipboard, switch view to plain text mode 

    and miospinbox.cpp

    Qt Code:
    1. #include "miospinbox.h"
    2.  
    3. miospinbox::miospinbox()
    4. {
    5. QLineEdit *lineedit = new QLineEdit(this);
    6. //QRegExp rx("-?\\d{1,3}");
    7. QRegExp rx("[1-9]\\d{0,3}");
    8. QValidator *validator = new QRegExpValidator(rx, this);
    9.  
    10. lineedit->setInputMask("\\X 0000\\, Y 0000, Z 0000, \\A 000, \\B 000, \\C 000;0");
    11. lineedit->setValidator(validator);
    12. setLineEdit(lineedit);
    13. }
    To copy to clipboard, switch view to plain text mode 

    The validator in not ok, I see this, but setInputMask I think is ok.
    When I show the myspinbox on the window, I'can not change the number with keyboard and I can not change with the mouse clicking on arrow of the spinbox.

  2. #2
    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: QAbstractSpinBox subclassing

    It won't work that way as the spinbox will try to change the value to int, resulting in always obtaining 0. You have to reimplement more methods (at least ones converting between text and value) to do what you require.

  3. #3
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QAbstractSpinBox subclassing

    Thank you

    where I can find a example?

  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: QAbstractSpinBox subclassing

    Hmm... actually it looks like I was wrong. You have to reimplement stepBy(). Oh, and you don't have to set a new lineedit to the widget, you can use the one that is already there.

Similar Threads

  1. QAbstractSpinBox Subclass exhibits wierd behavour
    By sunil.thaha in forum Qt Programming
    Replies: 6
    Last Post: 22nd February 2007, 13:30
  2. Problem with QTreeWidget after subclassing
    By steve918 in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2006, 19:51
  3. Problem in SubClassing QTableItem.
    By sumsin in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2006, 11:21
  4. Subclassing QScrollView
    By sumsin in forum Qt Programming
    Replies: 13
    Last Post: 16th March 2006, 15:20
  5. Subclassing
    By joseph in forum Newbie
    Replies: 1
    Last Post: 25th February 2006, 15:06

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.