Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-21217

QLineEdit copy shortcut does not work if isReadonly is true

    XMLWordPrintable

Details

    • 872b9b231ef966ce7b2b40785ee92a0d4a8d2851

    Description

      If you have an application that has a menu item whose shortcut is Cmd-C (or Ctrl-C on Windows) for copy, and also have a QLineEdit that is read only, you can select the text of the QLineEdit but pressing the standard copy shortcut does not copy the selected text to the clipboard. However, right clicking and choosing Copy does copy the text. If the QLineEdit is not read only, then the standard copy keyboard shortcut does copy the text to the clipboard.

      This bug is demonstrated in the attachment. If you compile and run it, there are two QLineEdit widgets. The top is editable, the bottom is read only. If you select the text in the top one and press Cmd/Ctrl-C, the text will be copied to the clipboard. If you do the same for the bottom widget, the text is not copied to the clipboard.

      The bug looks like it is in QLineControl::processEvent() of qlinecontrol.cpp, where there is this code:

              case QEvent::ShortcutOverride:{
                  if (isReadOnly())
                      return false;
                  QKeyEvent* ke = static_cast<QKeyEvent*>(ev);
                  if (ke == QKeySequence::Copy
                      || ke == QKeySequence::Paste
                      || ke == QKeySequence::Cut
                      || ke == QKeySequence::Redo
                      || ke == QKeySequence::Undo
                      || ke == QKeySequence::MoveToNextWord
                      || ke == QKeySequence::MoveToPreviousWord
                      || ke == QKeySequence::MoveToStartOfDocument
                      || ke == QKeySequence::MoveToEndOfDocument
                      || ke == QKeySequence::SelectNextWord
                      || ke == QKeySequence::SelectPreviousWord
                      || ke == QKeySequence::SelectStartOfLine
                      || ke == QKeySequence::SelectEndOfLine
                      || ke == QKeySequence::SelectStartOfBlock
                      || ke == QKeySequence::SelectEndOfBlock
                      || ke == QKeySequence::SelectStartOfDocument
                      || ke == QKeySequence::SelectAll
                      || ke == QKeySequence::SelectEndOfDocument) {
                      ke->accept();
      

      I think ignoring the event in all cases there makes sense for a read only widget except for the copy event.

      The attached file was tested on 4.7.2 but this part of qlinecontrol.cpp hasn't changed in the latest version in the Git repo so I expect that the bug still exists.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            peppe Giuseppe D'Angelo
            aclight Adam Light
            Votes:
            6 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes