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. [Solved] QTableView Edit with one click
QtWS25 Last Chance

[Solved] QTableView Edit with one click

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.9k Views
  • 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 Offline
    S Offline
    sharethl
    wrote on 26 Jun 2015, 20:45 last edited by sharethl
    #1

    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.

    S 1 Reply Last reply 26 Jun 2015, 20:53
    0
    • S sharethl
      26 Jun 2015, 20:45

      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.

      S Offline
      S Offline
      sharethl
      wrote on 26 Jun 2015, 20:53 last edited by sharethl
      #2

      @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);
      
      1 Reply Last reply
      0
      • F Offline
        F Offline
        flist
        wrote on 5 Aug 2017, 09:22 last edited by
        #3

        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;
        }

        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