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

QTreeView: Editor and context menu open at the same time

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • Not Evaluated
    • 4.7.0
    • 4.5.2
    • Widgets: Itemviews
    • None
    • WinXp SP3, VS 2005

    Description

      In a QTreeView an editor for an item and the treeview context menu can be invoked at the same time, when a left mouse click is followed
      by a right mouse click quickly.
      This shouldn't be possible, because a line edit has a context menu of its own.
      Furthermore, during an action invoked from the tree context menu the editor will possibly be closed and the model's setData() method will be called.
      This behaviour can lead to undesired results. In our case it spoiled the transaction logic of a CAD-Framework (two transactions overlapping, one triggered by context menu action, one by the closing editor)

      To reproduce the effect please extend the QT simpletreemodel example by the following code

      1) In treemodel.cpp add the ItemIsEditable flag:

      Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
      {
      ...
      return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
      }

      2) In main() create an instance of this this class instead of QTreeView

      class MyTreeView : public QTreeView
      {
      Q_OBJECT
      public:
      MyTreeView (QWidget * parent = 0 )
      : QTreeView(parent)

      { setEditTriggers(QAbstractItemView::SelectedClicked); }

      protected:
      virtual void contextMenuEvent( QContextMenuEvent * contextEv)

      { QMenu menuPopUp(this); menuPopUp.addAction(new QAction("Test", this)); menuPopUp.exec(contextEv->globalPos()); }

      };

      3) When you now left-click on an item, followed immediately by a right-click, first the item context menu will open, then the item edittor will occur.
      (see attached screenshot)

      Attachments

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

        Activity

          People

            dedietri Gabriel de Dietrich (drgvond)
            dieter Dieter Hammann
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes