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. Context menu breaks TreeView structure and selection
Forum Updated to NodeBB v4.3 + New Features

Context menu breaks TreeView structure and selection

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.8k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    tyapkov
    wrote on 26 Jan 2012, 12:12 last edited by
    #1

    We have faced recently the problem with context menu for the QTreeView. Context menu appears normally, but at the same time TreeView updates itself to the previous state. Consider folders. For example, if there are two folders in the TreeView. You open one of them and makes right click on the item inside. Then QTreeView shows the previous state, i.e. two collapsed folders. The second problem is that selection also jumpes to the one in the previous state.

    Here is the example of the code (Qt 4.7.4):

    @Viewer::Viewer(QWidget *parent) : QTreeView(parent)
    {
    setModel(&model);

    addFileAction = new QAction(tr("Add file"), this);
    projectMenu = new QMenu(this);
    projectMenu->addAction(addFileAction);
    
    setContextMenuPolicy(Qt::CustomContextMenu);
    connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint&)));
    

    }

    void ProjectViewer::showContextMenu(const QPoint& pos){

    QPoint globalPos = mapToGlobal(pos);
    projectMenu->exec(globalPos);
    

    }@

    All the answers are welcome!

    1 Reply Last reply
    0

    1/1

    26 Jan 2012, 12:12

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved