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. Disable selection of numbers in a QSpinBox
Forum Updated to NodeBB v4.3 + New Features

Disable selection of numbers in a QSpinBox

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 4.3k Views 1 Watching
  • 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
    pksublime
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Would setReadOnly(true) help in that case ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pksublime
        wrote on last edited by
        #3

        no because the spinbox becomes unusable, the user can no longer click the buttons to change the control's value. futher, readonly controls still allow for highlighting so that you can copy (a read function).

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then you could consider subclassing QSpinBox and provide a custom QLineEdit that has the behavior you want

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pksublime
            wrote on last edited by
            #5

            That's what I was afraid of. Never done that before. Any good examples?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @
              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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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