Results 1 to 7 of 7

Thread: QPlainTextEdit in delegate, how to confirm editing using TAB ?

  1. #1
    Join Date
    Jun 2016
    Posts
    19
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default QPlainTextEdit in delegate, how to confirm editing using TAB ?

    I am using QPlainTextEdit editor in QTableView text column delegate.
    Qt Code:
    1. QWidget * myDelegate_MLine::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
    2. {
    3. return new QPlainTextEdit(parent);
    4. }
    To copy to clipboard, switch view to plain text mode 
    THe only way I can complete/confirm QPlainTextEdit text changes is to click other column cell.
    I would like to override the TAB key press to confirm QPlainTextEdit editing and move to next column of the row (or using Ctrl+Enter to commit row and move to next row)

    I have other column delegate, using qlineedit, and when I press Enter when editing the cell, the row commits and focus stays on that field.
    I would like to achieve same behaviour, when editing cell using QPlainTextEdit, pressing Ctrl+Enter should commit the cell changes to the database and focus should be left on the QPlainTextEdit widget. Then pressing the TAB should move to next cell in the same row.
    Last edited by boo9; 16th June 2016 at 19:58.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPlainTextEdit in delegate, how to confirm editing using TAB ?

    You could install the delegate as an event fiilter on the editor and then react to tab.

    Cheers,
    _

  3. #3
    Join Date
    Jun 2016
    Posts
    19
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPlainTextEdit in delegate, how to confirm editing using TAB ?

    > then react to tab.
    I considered that, but I dont know what the reaction should be
    should I act on QPlainTextEdit->call() or else ?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPlainTextEdit in delegate, how to confirm editing using TAB ?

    Quote Originally Posted by boo9 View Post
    I considered that, but I dont know what the reaction should be
    I am afraid I don't understand. You said you wanted to commit the data and move to the next cell.

    Quote Originally Posted by boo9 View Post
    should I act on QPlainTextEdit->call() or else ?
    You act on the tab mouse press event that the event filter gets before it reaches the text edit.

    Cheers,
    _

  5. #5
    Join Date
    Jun 2016
    Posts
    19
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPlainTextEdit in delegate, how to confirm editing using TAB ?

    > I am afraid I don't understand

    Editing cell with default delegate:
    When I insert a new row in TableView (the new row gets "*" mark) and the cell is varchar(), I get standard delegate behaving like QLineEdit. After inputing the text I can
    - press TAB to move to next cell in the row (the "*" stays unchagned), or
    - press Enter/Return after which the row commits (the "*" changes to numeric row sequence) and the focus stays on current cell, the cell is selected.

    Editing cell with default my custom delegate (using QPlainTextEdit).
    When I insert a new row, and start editing a cell with my custom delegate, the row is marked "*", I want similar behaviour as above:
    1) pressing TAB should move focus to next cell (the row mark should stay "*")
    2) pressing Control+Enter should move focus commit row ("*" row mark should change to numeric) and focus should stay on the current cell and cell should be selected.

    I manage to figure out 1) by calling QPlainTextEdit->setTabChangesFocus(true)
    I dont know how to achive 2)

    I did subclass QPlainTextEdit with keyPressEvent() member so I can see all keys being sent.
    I am intercepting Key_Tab, or (Ctrl+Enter), but I dont know what code should I call to achive 2) behaviour
    I dont know what the code of QPlainTextEdit does to achive 1) when I call QPlainTextEdit->setTabChangesFocus(true); I would like to do similar for other key sequences.

    THis is what I have now
    Qt Code:
    1. class myMultiLineEdit : public QPlainTextEdit
    2. {
    3. public:
    4. myMultiLineEdit (QWidget * parent) : QPlainTextEdit(parent) {}
    5. virtual void keyPressEvent(QKeyEvent *ee)
    6. {
    7. if(ee->key() == Qt::Key_Tab)
    8. {
    9. qDebug() << "tab pressed";
    10. focusNextChild() || focusPreviousChild();
    11. }
    12. else
    13. QPlainTextEdit::keyPressEvent(ee);
    14. }
    15. };
    To copy to clipboard, switch view to plain text mode 

    but focusNextChild() || focusPreviousChild() does nothing, the editor control does not close and does not move to next cell.

    cheers
    Last edited by boo9; 17th June 2016 at 13:33.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPlainTextEdit in delegate, how to confirm editing using TAB ?

    I think if your editor wants to indicate that it is finished editing, then the delegate has to emit the commitData() signal.

    Cheers,
    _

  7. The following user says thank you to anda_skoa for this useful post:

    boo9 (17th June 2016)

  8. #7
    Join Date
    Jun 2016
    Posts
    19
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPlainTextEdit in delegate, how to confirm editing using TAB ?

    TAB works, thank you very much, exits editor and moves to editing next cell

    However, when the record is inserted ("*" record mark)
    this does not commit the row, the "*" mark stays and does not change to numeric row id.
    What do I need to do to commit the row to db (to change "*" to numeric), as default delegate does for varchar() columns ?

    EDIT:
    to commit the row one must call QAbstractItemModel::submit()

    Qt Code:
    1. void myDelegate_MLine::commitAndCloseEditor()
    2. {
    3. myMultiLineEdit *editor = qobject_cast<myMultiLineEdit *>(sender());
    4. emit commitData(editor);
    5. emit closeEditor(editor, QAbstractItemDelegate::EditNextItem);
    6. model->submit();
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by boo9; 17th June 2016 at 23:19.

Similar Threads

  1. Replies: 5
    Last Post: 30th October 2014, 20:40
  2. How to confirm the clean exit of QApplication
    By sraju in forum Qt Programming
    Replies: 7
    Last Post: 19th August 2014, 07:23
  3. Confirm text on QLineEdit
    By hassinoss in forum Newbie
    Replies: 2
    Last Post: 15th April 2014, 04:44
  4. Replies: 10
    Last Post: 10th August 2012, 15:51
  5. how to confirm the value of one QList in other QList quickly?
    By weixj2003ld in forum Qt Programming
    Replies: 5
    Last Post: 8th June 2012, 20:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.