Disable selection of numbers in a QSpinBox
-
I have a heavily styles QSpinBox for an embedded system (touchscreen only), and I have everything looking the way I want. The problem is that the device has a touchscreen and the users might click in the text area, or worse drag. This produces both a cursor and the numbers become highlighted.
I have a hokey solution for the highlighting, change the highlight color to transparent, and I'd like a better solution for this that hopefully also addresses having the cursor show on the screen.
-
Hi and welcome to devnet,
Would setReadOnly(true) help in that case ?
-
Then you could consider subclassing QSpinBox and provide a custom QLineEdit that has the behavior you want
-
@
MySpinBox::MySpinBox(QWidget *parent):
QSpinBox(parent)
{
setLineEdit(new MyLineEdit);
}MyLineEdit::MyLineEdit(QWidget *parent):
QLineEdit(parent)
{
setReadOnly(true);
}void MyLineEdit::mousePressEvent(QMouseEvent *)
{}void MyLineEdit::mouseMoveEvent(QMouseEvent *)
{}void MyLineEdit::mouseReleaseEvent(QMouseEvent *)
{}
@WARNING: Not tested but it should do the trick, there are other ways to do it (e.g. a simple event filter so you only need to subclass QSpinBox)
Hope it helps