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

QGraphicsTextItem input chinese and show preview text will input failed,when click on a blank area or TextItem lose focus.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Done
    • Affects Version/s: 5.11.3, 5.15.0
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      OS:deepin
      Qt Version: Qt5.11.3.9
      Compiler: x86_64-linux-gnu
      Executed from Qt Creator in Debug mode.
    • Platform/s:
      Linux/X11
    • Commits:
      3983afd48f27cdbb006720957ff34cf58f126ca5 (qt/qtbase/dev)

      Description

      step1:

          create a Qt GUI project and coding main.cpp as fllow:

      #include <QApplication>
      
      #include <QGraphicsScene>
      #include <QGraphicsView>
      #include <QGraphicsTextItem>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QGraphicsScene scene;
          QGraphicsView view(&scene);
          QGraphicsTextItem *simpleTextItem = new QGraphicsTextItem;
          simpleTextItem->setFlag(QGraphicsTextItem::ItemIsFocusScope);
          simpleTextItem->setTextInteractionFlags(Qt::TextEditorInteraction);
          simpleTextItem->setPlainText("QGraphicsTextItem");
          scene.addItem(simpleTextItem);
          view.show();
      
          return a.exec();
      }
      

      step2:

          run application and change the system input method with chinese, and then input chinese into application QGraphicsTextItem, at this time,textItem will show preview text,click scence blank area or change window display or minimize window,the application TextItem will selected preview text. but when you click or drag mouse cursor,the preview text will disappear, if you do nothing, the preview text always show. ******this enclosure packet contains a error.gif will show process.

      Reasons:

          The reason for this bug is that after the TextItem loses focus, the focusItem in QGraphicsScene is already empty. When QGraphicsScene responds to the inputMethodEvent event again, since focusItem is already empty, focusItem will no longer deliver events.

      fix:

          The solution to this bug is to let the last input textitem continue to respond to the inputMethodEvent event. The modified code on(widgets/graphicsview/qgraphicsscene.cpp).

      void QGraphicsScene::inputMethodEvent(QInputMethodEvent *event)
      {
          Q_D(QGraphicsScene);
          if (d->focusItem && (d->focusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) {
              d->sendEvent(d->focusItem, event);
              return;
          }
      
          if (d->lastFocusItem && d->lastFocusItem != d->focusItem && (d->lastFocusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod))
              d->sendEvent(d->lastFocusItem, event);
      }
      

      effect:

          When the textitem is in preview input, the focus is lost or the window is changed or the window is minimized, and the preview input text can be received.this enclosure packet contains a done.gif will show process.**

        Attachments

        1. done.gif
          done.gif
          395 kB
        2. error.gif
          error.gif
          445 kB
        3. image-2020-08-28-16-25-24-512.png
          image-2020-08-28-16-25-24-512.png
          210 kB
        4. test_code.zip
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            kingderzhang kingderzhang
            Reporter:
            kingderzhang kingderzhang
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes