[Solved] QTableView Edit with one click



  • I have to use inputMethod for input, no hardware keyboard.
    But there is a problem,
    Although I set all triggers to QTableView, one click did get cell in edit and can see the blinking cursor, virtual keyboard still not showing up.
    I have to click the editor again, then virtual keyboard could show up.
    Why is this? and I tried Delegates no helps. (Change to LineEdit, and post mouse click event to it, doesn't work either.)

    // working with combobox.
    void DisplayPolicyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    {
        Q_UNUSED(index);
        QComboBox *comboBox = qobject_cast<QComboBox*>(editor);
        if(comboBox==0) return;
        comboBox->showPopup();
    }
    

    PS: virtual keyboard could show up on line edit that is not in TableView.



  • @sharethl said:

    I have to use inputMethod for input, no hardware keyboard.
    But there is a problem,
    Although I set all triggers to QTableView, one click did get cell in edit and can see the blinking cursor, virtual keyboard still not showing up.
    I have to click the editor again, then virtual keyboard could show up.
    Why is this? and I tried Delegates no helps. (Change to LineEdit, and post mouse click event to it, doesn't work either.)

    // working with combobox.
    void DisplayPolicyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    {
        Q_UNUSED(index);
        QComboBox *comboBox = qobject_cast<QComboBox*>(editor);
        if(comboBox==0) return;
        comboBox->showPopup();
    }
    

    PS: virtual keyboard could show up on line edit that is not in TableView.

    Solved by pass event release. Not pressed.

        QMouseEvent* evt = new QMouseEvent(QEvent::MouseButtonRelease,
                                           QPointF(1,1), // Cannot use lineEdit->width()/2 somehow.
                                           Qt::LeftButton,
                                           Qt::LeftButton,
                                           Qt::NoModifier);
        QApplication::postEvent(lineEdit, evt);
    


  • Hi, I have a same question with you now.I used your method in the delegate, but it did not work. Can you help me with the details?
    My code is as follows:
    QWidget* createEditor(QWidget parent, const QStyleOptionViewItem & option,const QModelIndex & index) const
    {
    Q_UNUSED(option);
    Q_UNUSED(index);
    QLineEdit
    lineEdit = new QLineEdit(parent);
    connect(lineEdit,SIGNAL(textChanged(QString)),this,SLOT(slotPrivate_editorChanged(QString)));
    lineEdit->setMaxLength(_nameLength);
    QMouseEvent* evt = new QMouseEvent(QEvent::MouseButtonRelease, QPoint(1,1),Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
    QApplication::postEvent(lineEdit, evt);
    return lineEdit;
    }


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.