2

Half of my answer was found here: How to prevent QSpinBox from automatically highlighting contents

However, the program still allows for a mouse or touch-drag to highlight the values of the spinboxes. I need absolutely no highlighting as my application is for an embedded device interface.

How do completely disable highlighting of any kind while still maintaining the spinbox up/down button functionality.

pksublime
  • 191
  • 1
  • 11

3 Answers3

2

What we ended up doing was to connect a couple signals to the textEditDeselect slot.

foreach(QSpinBox* sb, ui.main->findChildren<QSpinBox*>())
{
    sb->findChildren<QLineEdit*> ().at(0)->setReadOnly(true);
    connect(sb,SIGNAL(valueChanged(int)),this,SLOT(textEditDeselect()), Qt::QueuedConnection);
    connect(sb->findChild<QLineEdit*> (), SIGNAL(cursorPositionChanged(int,int)),this,  SLOT(textEditDeselect()),Qt::QueuedConnection);
}
pksublime
  • 191
  • 1
  • 11
1

The easiest solution is to change the palette in Qt Designer.

Select qspinbox, click "Change Palette" and for HighlightedText choose black color. This will disable blue background, at least on windows.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
0

Another solution is to set the style sheet for the QSpinBox's QLineEdit. This effectively makes the selection color invisible.

Pyqt5:

tmpSpinBox = QSpinBox()
tmpSpinBox.linedit().setStyleSheet("""QLineEdit { 
                                       selection-background-color: white;
                                       selection-color: black 
                                   }""")
Matt Binford
  • 620
  • 8
  • 15