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. SpinBox and virtual Keyboard
Qt 6.11 is out! See what's new in the release blog

SpinBox and virtual Keyboard

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.1k Views 3 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.
  • T Offline
    T Offline
    Till Orly
    wrote on last edited by
    #1

    Hi community,

    I'm kind of a QT noob. I need a virtual keyboard, and it should be Qt widgets (customer want it that way).

    Now I found an easy to use and reuse approach from TI (http://processors.wiki.ti.com/index.php/Qt_Keyboard_Template) they open it using the selectionChanged() slot of a QLineEdit.

    Now what' the most QT way to open it when clicking into any SpinBox?

    Cheers Tillo

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

      Hi
      The very right way would be via
      http://doc.qt.io/qt-5/qinputmethod.html#details
      for true integration. ( as far as i know. not tried that class)

      However, if you only need for SpinBox, then maybe event filter to catch the click
      (pseudo code - yours is most likely MainWindow and not QDialog)

      in ctor
      ui->spinBox->installEventFilter(this);
      ...
      bool Dialog::eventFilter(QObject *o, QEvent *e)
      {
      	if (o == spinBox && e->type() ==  QEvent::MouseButtonPress ) {
      		e->ignore();
                     // pop keyboard
      		return true;
      	}
      	return QDialog::eventFilter(o, e);
      }
      

      alternative

      you can get its lineEdit and maybe do the same as sample ?
      QLineEdit *LE= ui->spinBox->findChild<QLineEdit*>();
      if (LE) {
      connect like sample
      }
      
      1 Reply Last reply
      1
      • T Offline
        T Offline
        Till Orly
        wrote on last edited by
        #3

        Thanks, the alternative worked like a charm.

        T 1 Reply Last reply
        1
        • T Till Orly

          Thanks, the alternative worked like a charm.

          T Offline
          T Offline
          Till Orly
          wrote on last edited by Till Orly
          #4

          @mrjj Actually the alternative had a flaw. Since it uses selectionChanged() and the text in a SpinBox get selected when clicking on one of the arrows...

          The solution I came up with, using customContextMenuRequested():

              spinBox->setContextMenuPolicy(Qt::CustomContextMenu);
              connect(spinBox,&QLineEdit::customContextMenuRequested,this,&dialog::openKbLineEdit);
          

          and the fitting slot

          void dialog::openKbLineEdit()
          {
              QLineEdit *line;
              if(typeid(sender()) != typeid(QLineEdit)){
                  line = sender()->findChild<QLineEdit*>();
              } else{
                  line = (QLineEdit *)sender();
              }
              lineEditkeyboard->setLineEdit(line);
              lineEditkeyboard->show();
          }
          

          Oh, yeah no .ui involved here.

          1 Reply Last reply
          1
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            Super
            but i wish you would use
            qobject_cast
            and not c cast. in
            line = (QLineEdit *)sender();

            But im just old school :)
            As c cast are bad and qobject_cast is the way to cast Qt types.

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

              @mrjj it's not old school, qobject_cast is the right tool when casting QObject based objects.

              C style cast doesn't offer any guarantee that you are casting anything compatible.

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

              mrjjM 1 Reply Last reply
              2
              • SGaistS SGaist

                @mrjj it's not old school, qobject_cast is the right tool when casting QObject based objects.

                C style cast doesn't offer any guarantee that you are casting anything compatible.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @SGaist

                Thanks. It came out wrong.

                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