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
#include <QWidget>
#include <QAbstractSpinBox>
#include <QLineEdit>
#include <QValidator>
{
Q_OBJECT
public:
miospinbox();
};
#include <QWidget>
#include <QAbstractSpinBox>
#include <QLineEdit>
#include <QValidator>
class miospinbox : public QAbstractSpinBox
{
Q_OBJECT
public:
miospinbox();
};
To copy to clipboard, switch view to plain text mode
and miospinbox.cpp
#include "miospinbox.h"
miospinbox::miospinbox()
{
//QRegExp rx("-?\\d{1,3}");
lineedit->setInputMask("\\X 0000\\, Y 0000, Z 0000, \\A 000, \\B 000, \\C 000;0");
lineedit->setValidator(validator);
setLineEdit(lineedit);
}
#include "miospinbox.h"
miospinbox::miospinbox()
{
QLineEdit *lineedit = new QLineEdit(this);
//QRegExp rx("-?\\d{1,3}");
QRegExp rx("[1-9]\\d{0,3}");
QValidator *validator = new QRegExpValidator(rx, this);
lineedit->setInputMask("\\X 0000\\, Y 0000, Z 0000, \\A 000, \\B 000, \\C 000;0");
lineedit->setValidator(validator);
setLineEdit(lineedit);
}
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.
Bookmarks