Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Virtual keyboard code using qwidget.



  • Hello, every! This is the code for virtual keyboard inputting. It uses line edit to store content created by virtual keyboard. After users clicking button "enter", virtual keyboard disappears, leaving content in the line edit control. If anyone thinks it benifit your project, take it without any thank!

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>keyboard_dialog</class>
     <widget class="QDialog" name="keyboard_dialog">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>800</width>
        <height>240</height>
       </rect>
      </property>
      <layout class="QGridLayout" name="gridLayout">
       <property name="leftMargin">
        <number>0</number>
       </property>
       <property name="topMargin">
        <number>0</number>
       </property>
       <property name="rightMargin">
        <number>0</number>
       </property>
       <property name="bottomMargin">
        <number>0</number>
       </property>
       <property name="spacing">
        <number>0</number>
       </property>
       <item row="1" column="0">
        <widget class="customPushButtonBeep" name="one_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>1</string>
         </property>
        </widget>
       </item>
       <item row="1" column="1">
        <widget class="customPushButtonBeep" name="two_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>2</string>
         </property>
        </widget>
       </item>
       <item row="1" column="2">
        <widget class="customPushButtonBeep" name="three_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>3</string>
         </property>
        </widget>
       </item>
       <item row="1" column="3">
        <widget class="customPushButtonBeep" name="foure_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>4</string>
         </property>
        </widget>
       </item>
       <item row="1" column="4">
        <widget class="customPushButtonBeep" name="five_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>5</string>
         </property>
        </widget>
       </item>
       <item row="1" column="5">
        <widget class="customPushButtonBeep" name="six_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>6</string>
         </property>
        </widget>
       </item>
       <item row="1" column="6">
        <widget class="customPushButtonBeep" name="seven_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>7</string>
         </property>
        </widget>
       </item>
       <item row="1" column="7">
        <widget class="customPushButtonBeep" name="eight_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>8</string>
         </property>
        </widget>
       </item>
       <item row="1" column="8">
        <widget class="customPushButtonBeep" name="nine_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>9</string>
         </property>
        </widget>
       </item>
       <item row="1" column="9">
        <widget class="customPushButtonBeep" name="zero_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>0</string>
         </property>
        </widget>
       </item>
       <item row="2" column="0">
        <widget class="customPushButtonBeep" name="q_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>Q</string>
         </property>
        </widget>
       </item>
       <item row="2" column="1">
        <widget class="customPushButtonBeep" name="w_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>W</string>
         </property>
        </widget>
       </item>
       <item row="2" column="2">
        <widget class="customPushButtonBeep" name="e_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>E</string>
         </property>
        </widget>
       </item>
       <item row="2" column="3">
        <widget class="customPushButtonBeep" name="r_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>R</string>
         </property>
        </widget>
       </item>
       <item row="2" column="4">
        <widget class="customPushButtonBeep" name="t_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>T</string>
         </property>
        </widget>
       </item>
       <item row="2" column="5">
        <widget class="customPushButtonBeep" name="y_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>Y</string>
         </property>
        </widget>
       </item>
       <item row="2" column="6">
        <widget class="customPushButtonBeep" name="u_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>U</string>
         </property>
        </widget>
       </item>
       <item row="2" column="7">
        <widget class="customPushButtonBeep" name="i_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>I</string>
         </property>
        </widget>
       </item>
       <item row="2" column="8">
        <widget class="customPushButtonBeep" name="o_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>O</string>
         </property>
        </widget>
       </item>
       <item row="2" column="9">
        <widget class="customPushButtonBeep" name="p_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>P</string>
         </property>
        </widget>
       </item>
       <item row="3" column="0">
        <widget class="customPushButtonBeep" name="a_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>A</string>
         </property>
        </widget>
       </item>
       <item row="3" column="1">
        <widget class="customPushButtonBeep" name="s_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>S</string>
         </property>
        </widget>
       </item>
       <item row="3" column="2">
        <widget class="customPushButtonBeep" name="d_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>D</string>
         </property>
        </widget>
       </item>
       <item row="3" column="3">
        <widget class="customPushButtonBeep" name="f_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>F</string>
         </property>
        </widget>
       </item>
       <item row="3" column="4">
        <widget class="customPushButtonBeep" name="g_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>G</string>
         </property>
        </widget>
       </item>
       <item row="3" column="5">
        <widget class="customPushButtonBeep" name="h_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>H</string>
         </property>
        </widget>
       </item>
       <item row="3" column="6">
        <widget class="customPushButtonBeep" name="j_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>J</string>
         </property>
        </widget>
       </item>
       <item row="3" column="7">
        <widget class="customPushButtonBeep" name="k_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>K</string>
         </property>
        </widget>
       </item>
       <item row="3" column="8">
        <widget class="customPushButtonBeep" name="l_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>L</string>
         </property>
        </widget>
       </item>
       <item row="3" column="9">
        <widget class="customPushButtonBeep" name="tilde_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>~</string>
         </property>
        </widget>
       </item>
       <item row="4" column="0">
        <widget class="customPushButtonBeep" name="z_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>Z</string>
         </property>
        </widget>
       </item>
       <item row="4" column="1">
        <widget class="customPushButtonBeep" name="x_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>X</string>
         </property>
        </widget>
       </item>
       <item row="4" column="2">
        <widget class="customPushButtonBeep" name="c_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>C</string>
         </property>
        </widget>
       </item>
       <item row="4" column="3">
        <widget class="customPushButtonBeep" name="v_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>V</string>
         </property>
        </widget>
       </item>
       <item row="4" column="4">
        <widget class="customPushButtonBeep" name="b_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>B</string>
         </property>
        </widget>
       </item>
       <item row="4" column="5">
        <widget class="customPushButtonBeep" name="n_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>N</string>
         </property>
        </widget>
       </item>
       <item row="4" column="6">
        <widget class="customPushButtonBeep" name="m_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>M</string>
         </property>
        </widget>
       </item>
       <item row="4" column="7">
        <widget class="customPushButtonBeep" name="plus_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>+</string>
         </property>
        </widget>
       </item>
       <item row="4" column="8">
        <widget class="customPushButtonBeep" name="minus_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>-</string>
         </property>
        </widget>
       </item>
       <item row="4" column="9">
        <widget class="customPushButtonBeep" name="point_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>=</string>
         </property>
        </widget>
       </item>
       <item row="5" column="2">
        <widget class="customPushButtonBeep" name="underscore_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>_</string>
         </property>
        </widget>
       </item>
       <item row="0" column="0" colspan="8">
        <widget class="customLineEdit" name="TextEdit">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
        </widget>
       </item>
       <item row="0" column="8" colspan="2">
        <widget class="customPushButtonBeep" name="backspace_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>&lt;-- Backspace</string>
         </property>
        </widget>
       </item>
       <item row="5" column="8" colspan="2">
        <widget class="customPushButton" name="enter_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="styleSheet">
          <string notr="true">border:1px solid;
    background-color: rgb(0, 170, 0);
    border-color: rgb(255, 255, 255);
    color: rgb(255, 255, 255);</string>
         </property>
         <property name="text">
          <string>Enter</string>
         </property>
        </widget>
       </item>
       <item row="5" column="6" colspan="2">
        <widget class="customPushButton" name="exit_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="styleSheet">
          <string notr="true">border:1px solid;
    background-color: rgb(170, 0, 0);
    border-color: rgb(255, 255, 255);
    color: rgb(255, 255, 255);</string>
         </property>
         <property name="text">
          <string>Cancel</string>
         </property>
        </widget>
       </item>
       <item row="5" column="3" colspan="3">
        <widget class="customPushButtonBeep" name="space_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>Space</string>
         </property>
        </widget>
       </item>
       <item row="5" column="0" colspan="2">
        <widget class="customPushButtonBeep" name="shift_btn">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <property name="text">
          <string>Shift</string>
         </property>
        </widget>
       </item>
      </layout>
     </widget>
     <customwidgets>
      <customwidget>
       <class>customPushButton</class>
       <extends>QPushButton</extends>
       <header location="global">other/customWidget.h</header>
      </customwidget>
      <customwidget>
       <class>customLineEdit</class>
       <extends>QLineEdit</extends>
       <header location="global">other/customWidget.h</header>
      </customwidget>
      <customwidget>
       <class>customPushButtonBeep</class>
       <extends>QPushButton</extends>
       <header location="global">other/customWidget.h</header>
      </customwidget>
     </customwidgets>
     <resources/>
     <connections/>
    </ui>
    
    
    #ifndef KEYBOARD_DIALOG_H
    #define KEYBOARD_DIALOG_H
    
    #include <QDialog>
    #include <QButtonGroup>
    //#include "ui_keyboard_dialog.h"
    #include "other/htdialog.h"
    //#include "other/customWidget.h"
    
    
    namespace Ui {
    class keyboard_dialog;
    }
    
    class keyboard_dialog : public QDialog
    {
        Q_OBJECT
    
    public:
        explicit keyboard_dialog(QWidget *parent = 0);
        ~keyboard_dialog();
    
        void setLineEdit(QString filename);   //initialize textedit content
    
    private:
        QButtonGroup *buttongroup;
        bool shiftflag;
        int MAXINPUTSIZE;
        Ui::keyboard_dialog *ui;
    signals:
        void sendtext(QString);
        void SendClose();
    private slots:
        void on_enter_btn_clicked();
        void ButtonJudge(int);
    
        void on_exit_btn_clicked();
    private:
        void setKeyBoard();
        void setCapital();
        void setlowercase();
        void reject();
    
    public slots:
        void system_cancel();
    
    };
    
    #endif // KEYBOARD_DIALOG_H
    
    
    #include "keyboard_dialog.h"
    #include "ui_keyboard_dialog.h"
    
    #include "mainwindow.h"
    
    extern QList<QDialog *> *ht_dialog_list;
    
    extern MainWindow *mainw_global;
    
    keyboard_dialog::keyboard_dialog(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::keyboard_dialog)
    {
        parent = parent;
        ui->setupUi(this);
        shiftflag = 1;
        buttongroup = 0;
        buttongroup = new QButtonGroup(this);
    
        //set window model mode
        this->setWindowFlags(Qt::FramelessWindowHint|Qt::Dialog);
    
        this->setFixedSize(700*mainw_global->width_scale,240*mainw_global->height_scale);
        ui->tilde_btn->setFont(QFont("Microsoft YaHei",mainw_global->sys_symbol_font));
        ui->point_btn->setFont(QFont("Microsoft YaHei",mainw_global->sys_symbol_font));
        ui->minus_btn->setFont(QFont("Microsoft YaHei",mainw_global->sys_symbol_font));
        ui->plus_btn->setFont(QFont("Microsoft YaHei",mainw_global->sys_symbol_font));
    
    #if !PC_DEBUG
        this->move(50*mainw_global->width_scale,mainw_global->sys_height-280*mainw_global->height_scale);
    #endif
    
        this->setAutoFillBackground(true);
        QPalette palette;
        QBrush qb;
        palette.setBrush(QPalette::Background,qb);
        this->setPalette(palette);
    
        setKeyBoard();
    
        //set max input length
        ui->TextEdit->setMaxLength(20);
        connect(buttongroup,SIGNAL(buttonClicked (int)),this,SLOT(ButtonJudge(int)));
    
        //set qdialog property
        setProperty("type",DIALOG_TYPE_KEYALLBD);
        //enter QDialog into queue
        ht_dialog_list->append(this);
    
        ui->exit_btn->setShortcut(Qt::Key_F8);
    }
    
    keyboard_dialog::~keyboard_dialog()
    {
        //clean monitoring queue's corresponding QDialog
        int index = ht_dialog_list->indexOf(this);
        if (-1 != index)
        {
            ht_dialog_list->removeAt(index);
        }
        if (buttongroup) {
            delete buttongroup;
            buttongroup = 0;
        }
        if (ui) {
            delete ui;
            ui = 0;
        }
    }
    
    //enter command
    void keyboard_dialog::on_enter_btn_clicked()
    {
        QString str;
        str = ui->TextEdit->text();
        if(!mainw_global->keyboard_flag)
        {
            if (!str.isEmpty())
            {
                emit sendtext(str);
            }else
            {
                HTDialog::warning(NULL,tr("system error"), tr("file name can not be empty!"));
            }
        }else{
            mainw_global->keyboard_flag = false;
            emit sendtext(str);
        }
    }
    
    //configure keyboard
    void keyboard_dialog::setKeyBoard() {
        buttongroup->addButton(ui->one_btn, Qt::Key_1);
        buttongroup->addButton(ui->two_btn, Qt::Key_2);
        buttongroup->addButton(ui->three_btn, Qt::Key_3);
        buttongroup->addButton(ui->foure_btn, Qt::Key_4);
        buttongroup->addButton(ui->five_btn, Qt::Key_5);
        buttongroup->addButton(ui->six_btn, Qt::Key_6);
        buttongroup->addButton(ui->seven_btn, Qt::Key_7);
        buttongroup->addButton(ui->eight_btn, Qt::Key_8);
        buttongroup->addButton(ui->nine_btn, Qt::Key_9);
        buttongroup->addButton(ui->zero_btn, Qt::Key_0);
        buttongroup->addButton(ui->q_btn, Qt::Key_Q);
        buttongroup->addButton(ui->w_btn, Qt::Key_W);
        buttongroup->addButton(ui->e_btn, Qt::Key_E);
        buttongroup->addButton(ui->r_btn, Qt::Key_R);
        buttongroup->addButton(ui->t_btn, Qt::Key_T);
        buttongroup->addButton(ui->y_btn, Qt::Key_Y);
        buttongroup->addButton(ui->u_btn, Qt::Key_U);
        buttongroup->addButton(ui->i_btn, Qt::Key_I);
        buttongroup->addButton(ui->o_btn, Qt::Key_O);
        buttongroup->addButton(ui->p_btn, Qt::Key_P);
        buttongroup->addButton(ui->a_btn, Qt::Key_A);
        buttongroup->addButton(ui->s_btn, Qt::Key_S);
        buttongroup->addButton(ui->d_btn, Qt::Key_D);
        buttongroup->addButton(ui->f_btn, Qt::Key_F);
        buttongroup->addButton(ui->g_btn, Qt::Key_G);
        buttongroup->addButton(ui->h_btn, Qt::Key_H);
        buttongroup->addButton(ui->j_btn, Qt::Key_J);
        buttongroup->addButton(ui->k_btn, Qt::Key_K);
        buttongroup->addButton(ui->l_btn, Qt::Key_L);
        buttongroup->addButton(ui->z_btn, Qt::Key_Z);
        buttongroup->addButton(ui->x_btn, Qt::Key_X);
        buttongroup->addButton(ui->c_btn, Qt::Key_C);
        buttongroup->addButton(ui->v_btn, Qt::Key_V);
        buttongroup->addButton(ui->b_btn, Qt::Key_B);
        buttongroup->addButton(ui->n_btn, Qt::Key_N);
        buttongroup->addButton(ui->m_btn, Qt::Key_M);
    //    buttongroup->addButton(ui->space_btn, Qt::Key_Space);
        buttongroup->addButton(ui->underscore_btn,Qt::Key_Underscore);
        buttongroup->addButton(ui->backspace_btn, Qt::Key_Backspace);
        buttongroup->addButton(ui->shift_btn, Qt::Key_Shift);
        buttongroup->addButton(ui->minus_btn,Qt::Key_Minus);
        buttongroup->addButton(ui->plus_btn,Qt::Key_Plus);
        buttongroup->addButton(ui->point_btn,Qt::Key_Equal);
        buttongroup->addButton(ui->tilde_btn,Qt::Key_AsciiTilde);
    }
    
    //button command action
    void keyboard_dialog::ButtonJudge(int id)
    {
        QString temp;
        if((id >= Qt::Key_0)&&(id <= Qt::Key_9))
        {
            ui->TextEdit->insert(QString::number(id - Qt::Key_0));
        }else if((id >= Qt::Key_A)&&(id <= Qt::Key_Z))
        {
            id += shiftflag?0x20:0;
            temp = id;
            ui->TextEdit->insert(temp);
        }else
        {
            if(id == Qt::Key_Shift)
            {
                shiftflag = !shiftflag;
                if(!shiftflag)
                {
                    ui->shift_btn->setStyleSheet("border:1px solid;"
                                                 "background-color: rgb(0, 0, 0,120);"
                                                 "border-color: rgb(255, 255, 255);"
                                                 "color: rgb(0, 255, 0);");
                }else
                {
                    ui->shift_btn->setStyleSheet("border:1px solid;"
                                                 "background-color: rgb(0, 0, 0,120);"
                                                 "border-color: rgb(255, 255, 255);"
                                                 "color: rgb(255, 255, 255);");
                }
            }else if(id == Qt::Key_Backspace)
            {
                ui->TextEdit->backspace();
            }else
            {
                temp = id;
                ui->TextEdit->insert(temp);
            }
        }
    }
    
    void keyboard_dialog::on_exit_btn_clicked()
    {
        mainw_global->keyboard_flag = false;
        emit SendClose();
    }
    
    //destorying system window
    void keyboard_dialog::system_cancel()
    {
        emit SendClose();
    }
    
    void keyboard_dialog::setLineEdit(QString filename)
    {
        ui->TextEdit->setText(filename);
        ui->TextEdit->selectAll();
        ui->TextEdit->setFocus();
    }
    
    void keyboard_dialog::reject()
    {
    
    }
    
    

Log in to reply