Results 1 to 6 of 6

Thread: Right click list - some advice ?

  1. #1
    Join Date
    Oct 2008
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Right click list - some advice ?

    I want to create a right click list. I couldn't find any appropriate class doing directly that, so I started creating one. I made a custom class inheriting QWidget, which has a QList of QLabel in a QGridLayout, so they end up one under the other. I adjusted it generally to look like a right click list. The problem is, I want to make it close when there is mouse click event not in the widget's area. So, I wanted to ask, if there is some function for global mouse click event, which intercepts the mouse click event of a specific object, and which will then allow the program to continue as normal, calling the individual's object mouse click event ?

    Also, in QWidget there is no mouse hover event. Is there any way, besides doing it the hard way, to know over which labels the cursor is ?

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Right click list - some advice ?

    just curious: what is a right click list?

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Right click list - some advice ?

    I suppose "right click list" means QWidget::contextMenuEvent() + QMenu.
    J-P Nurmi

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Right click list - some advice ?

    So if your "right click list" is a context menu (also known as "popup menu") you can do something like this:
    Qt Code:
    1. void SomeWidget::contextMenuEvent(QContextMenuEvent* e)
    2. {
    3. QMenu* m = new QMenu(this);
    4. m->addAction(tr("parabola"));
    5. m->addAction(tr("karoseria"));
    6. m->addAction(tr("kulomiot"));
    7.  
    8. m->move(mapToGlobal(e->pos()));
    9. m->show();
    10. }
    To copy to clipboard, switch view to plain text mode 
    Where SomeWidget is a widget where you want your context menu to appear in. In this example you will have 3 element menu (list).

  5. #5
    Join Date
    Oct 2008
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Smile Re: Right click list - some advice ?

    Quote Originally Posted by caduel View Post
    just curious: what is a right click list?
    Yeah, you 're right, it wasn't such a good description, I am sorry.

    @all other:

    thanx, I was hoping that there is sth already implemented for this kind of things.

    I will look them.

    Thanx

  6. #6
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Right click list - some advice ?

    for simple cases you might just add the actions to the widget and set QWidget::setContextMenuPolicy() to Qt::ActionsContextMenu

Similar Threads

  1. Double Click Capturing
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2011, 14:12
  2. QFtp hidden files/folder's list
    By jay in forum Qt Programming
    Replies: 1
    Last Post: 26th December 2008, 12:12
  3. Replies: 2
    Last Post: 19th September 2008, 05:21
  4. Replies: 1
    Last Post: 22nd October 2007, 02:04
  5. QGraphicsScene Click / Double Click
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 04:32

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.