Results 1 to 2 of 2

Thread: Contextmenu in Qtreeview

  1. #1
    Join Date
    May 2007
    Location
    Germany
    Posts
    89
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Contextmenu in Qtreeview

    Hello friends,

    I have create an actions like this
    Qt Code:
    1. myAction = new QAction(QIcon(":/IMAGES/error.png"),tr("&TestAction"), this);
    2. connect(myAction, SIGNAL(triggered()), this, SLOT(openFileInTable( const QModelIndex & )));
    To copy to clipboard, switch view to plain text mode 

    Before creating my action I make this:

    Qt Code:
    1. trackFolder->setContextMenuPolicy(Qt::CustomContextMenu);
    2. connect(trackFolder, SIGNAL(customContextMenuRequested(const QPoint &)),
    3. this, SLOT(showContextMenu(const QPoint &)));
    To copy to clipboard, switch view to plain text mode 

    My contextmenu function is(trackfolder is a Qtreeview) :
    Qt Code:
    1. void Window::showContextMenu(const QPoint &position)
    2. {
    3.  
    4. QList<QAction *> actions;
    5. if (trackFolder->indexAt(position).isValid()) {
    6. actions.append(myAction);
    7. }
    8. if (actions.count() > 0)
    9. QMenu::exec(actions, trackFolder->mapToGlobal(position));
    10. }
    To copy to clipboard, switch view to plain text mode 

    So when I rightclick an item it shows me correctly the item, but the given function does not enter. But when I replace
    Qt Code:
    1. ....SLOT(openFileInTable( const QModelIndex & )));
    To copy to clipboard, switch view to plain text mode 
    with the normal quit function like this
    Qt Code:
    1. ....SLOT(quit()));
    To copy to clipboard, switch view to plain text mode 

    the Application quits normally.

    What do I wrong. My Slot in the contextmenu that must be run is declared like this:
    Qt Code:
    1. void openFileInTable(const QModelIndex & index);
    To copy to clipboard, switch view to plain text mode 

    How can I run my slot in the contextmenu???

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Contextmenu in Qtreeview

    You cannot connect
    Qt Code:
    1. void triggered()
    To copy to clipboard, switch view to plain text mode 
    with
    Qt Code:
    1. void openFileInTable( const QModelIndex & )
    To copy to clipboard, switch view to plain text mode 
    because the functions have different signatures. You have to scrap the "const QModelIndex &" argument.

    One solution would be to apply the selected action on the selected item(s) in the model.

Similar Threads

  1. QTreeView repaint
    By graeme in forum Qt Programming
    Replies: 17
    Last Post: 13th March 2012, 13:27
  2. Modify a ContextMenu
    By smarinr in forum Qt Programming
    Replies: 5
    Last Post: 10th May 2008, 17:41
  3. QTreeView help
    By bepaald in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 21:22
  4. QTreeView: Holding a line on screen
    By gri in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 11:42
  5. background image in QTreeView
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 06:25

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.