Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved virtual numpad for qt4.8

    Mobile and Embedded
    3
    3
    2606
    Loading More Posts
    • 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.
    • S
      sandycoolxyz last edited by

      Hello,
      I am using Qt4.8 .
      I wanted to use a virtual keypad for lineedits. (Numpad pops up when u click lineedits). Can be a normal keyboard as well.
      Is there any exisiting project I can use or should I reinvent the wheel ?

      Regards,
      Sandeep

      V 1 Reply Last reply Reply Quote 0
      • V
        VRonin @sandycoolxyz last edited by

        @sandycoolxyz said in virtual numpad for qt4.8:

        should I reinvent the wheel ?

        Not a huge wheel to reinvent as long as you are willing to stick to Arab numbers.

        #include <QWidget>
        #include <QGridLayout>
        #include <QLocale>
        #include <QSignalMapper>
        #include <QPushButton>
        class NumPad : public QWidget{
            Q_OBJECT
            Q_DISABLE_COPY(NumPad)
        public:
            explicit NumPad(QWidget* parent=0)
                :QWidget(parent)
            {
                setWindowTitle(tr("Numpad"));
                QGridLayout* mainLay=new QGridLayout(this);
                QSignalMapper* mainMapper = new QSignalMapper(this);
                connect(mainMapper,SIGNAL(mapped(int)),this,SIGNAL(numKeyPressed(int)));
                QPushButton* zeroButton =new QPushButton(locale().toString(0),this);
                mainLay->addWidget(zeroButton,3,1);
                mainMapper->setMapping(zeroButton,0);
                connect(zeroButton,SIGNAL(clicked()),mainMapper,SLOT(map()));
                mainLay->addItem(new QSpacerItem(1,1),3,0);
                mainLay->addItem(new QSpacerItem(1,1),3,2);
                for(int i=1;i<=9;++i){
                    QPushButton* singleButton =new QPushButton(locale().toString(i),this);
                    mainLay->addWidget(singleButton,(i-1)/3,(i-1)%3);
                    mainMapper->setMapping(singleButton,i);
                    connect(singleButton,SIGNAL(clicked()),mainMapper,SLOT(map()));
                }
            }
            Q_SIGNAL void numKeyPressed(int val);
        };
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply Reply Quote 3
        • mrjj
          mrjj Lifetime Qt Champion last edited by

          Hi
          Nice poor mans version. :)
          There is also
          http://doc.qt.io/qt-4.8/qt-tools-inputpanel-example.html
          Using RequestSoftwareInputPanel event.
          I assume the Qt keyboard uses these ?

          1 Reply Last reply Reply Quote 3
          • First post
            Last post