Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDoubleSpinBox..How to clear selected/highlighted text?
QtWS25 Last Chance

QDoubleSpinBox..How to clear selected/highlighted text?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 11.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PSI-lbc
    wrote on last edited by A Former User
    #1

    When I click the arrow buttons of a QDoubleSpinBox the text is highlighted (selected?) at the click. This is probably normal, but the highlighting makes it harder to read the numbers in the attached QLineEdit

    I have tried just about everything to get rid of the highlighting.

    clearFocus()
    change focus to another widget
    access the pointer to the QLineEdit (QLineEdit * QAbstractSpinBox::lineEdit () const ) and then deselect()
    clear() and then setValue()
    tried setting all the different focusPolicy possibilites
    tried changing the stylesheet highlight text color to not the blue highlight color

    Is there something I'm missing?

    1 Reply Last reply
    0
    • BilbonSacquetB Offline
      BilbonSacquetB Offline
      BilbonSacquet
      wrote on last edited by
      #2

      Could give the parameters of your QDoubleSpinBox ?

      1 Reply Last reply
      0
      • BilbonSacquetB Offline
        BilbonSacquetB Offline
        BilbonSacquet
        wrote on last edited by
        #3

        Anyway I reproduce it! :)

        The selection is done through: @myDoubleSpinBox->lineEdit()->selectAll();@
        And the solution is to call internally:
        @this->lineEdit()->deselect();@
        (like you suggest)
        Now the problem is 'when' you do this! If you do it in the slot which gets the values it's too early, the selectAll() is done AFTER the signal valueChanged()!

        If 'only' the steps (+/-) are the problem, inherits the QDoubleSpinBox and redefine the stepBy() function like this:
        @
        void MyDoubleSpinBox::stepBy(int steps)
        {
        QDoubleSpinBox::stepBy(steps);

        lineEdit()->deselect();
        

        }
        @

        Pay attention that you regenerate/recompile too the .ui files which reference your double spinboxes.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          PSI-lbc
          wrote on last edited by
          #4

          Thanks...

          Could give (you) the parameters of your QDoubleSpinBox ?
          They're all the standard settings as the QDoubleSpinBox is dropped on a form using Qt Creator. The ui-> convention used below is the Creator generated code in the .h file

          @private:
          Ui::form *ui;@

          Now the problem is ‘when’ you do this! If you do it in the slot which gets the values it’s too early

          Doh! That's when I was trying everything...in the valueChanged slot...

          @void form::on_dsb_valueChanged(double val)@

          I tried moving the deselect() call to the editingFinished slot for the dsb...

          @void form::on_dsb_editingFinished()
          {
          ui->dsb->lineEdit()->deselect();
          }@

          ..but get the error..

          /Library/Frameworks/QtGui.framework/Headers/qabstractspinbox.h:157: error: 'QLineEdit* QAbstractSpinBox::lineEdit() const' is protected within this context

          I also tried mapping the editingFinished signal to a generic slot and casting the widget pointer to a dsb...same error as above..protected

          @void form::dsbEditFinishedDeselect(QWidget *obj)
          {
          #if DEBUG_SYNCH
          qDebug() << "*form::dsbEditFinishedDeselect " ;
          #endif

          QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox *>(obj);
          dsb->lineEdit()->deselect();
          }@

          Not sure that it matters, but this is on a Mac..haven't tried it on my Win7 dev box, yet.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            PSI-lbc
            wrote on last edited by
            #5

            Cheesy, but this works...

            @void form::dsbEditFinishedDeselect(QWidget *obj)
            {
            #if DEBUG_SYNCH
            qDebug() << "*form::dsbEditFinishedDeselect " ;
            #endif

            QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox *>(obj);
            QString nohighlights = "color: black; background: white; selection-color: black; selection-background-color: white;"

            dsb->setStyleSheet( nohighlights );

            }@

            1 Reply Last reply
            0
            • C Offline
              C Offline
              chmedlymedly
              wrote on last edited by chmedlymedly
              #6

              I'm looking for a solution to the highlighting problem with QSpinBox. But, for PyQt5. I have key commands that drive spinbox up and down buttons and this is where I have the most trouble with the spinbox value being left highlighted even when the widget with focus changes via another key command. This highlighting doesn't stay behind when clicking with a mouse. One potential clue that I notice is that sometimes when changing the value (with these key commands) the highlighting changes from the value to the suffix of the spinbox (my values have a text suffix added) when finished. But, when I change a value again it immediately highlights the value again. Sorry if I'm not describing this clearly.

              I've tried creating a function that calls deselect on the QLineEdit inside of the QSpinBox but it's not working. I've tried connecting this function with 'editingFinished' and I don't get an error but it doesn't work either.

              Generally it looks something like this:

              child = QtCore.QObject.sender(self)
              mychild = child.findChild(QtWidgets.QLineEdit)
              mychild.deselect()
              

              I'm not well versed in C++ and so I'm wondering how to implement the previous 'cheesy' post. I think it's just setting a StyleSheet instead of the deselect? I've had a lot of trouble with StyleSheets changing font size and causing a ruckus so I'd like to find a different solution. This seems like such a dumb issue; I'm having trouble understanding why it exists in Qt at all...

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved