Results 1 to 2 of 2

Thread: Context menu long left click on QGraphicsTextItem

  1. #1
    Join Date
    Jun 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Question Context menu long left click on QGraphicsTextItem

    Hello,
    I try to have a context menu in Qt if we do a long press on a QGraphicsItemGroup. I have try basic thing like this:
    my .h:
    Qt Code:
    1. class myclass: public QMainWindow
    2. {
    3. Q_OBJECT
    4. public:
    5. myclass(QWidget *parent = 0);
    6. ~myclass();
    7.  
    8. public slots:
    9. void contextMenuEvent(QContextMenuEvent *event);
    10.  
    11. private:
    12. Ui::myclassClass ui;
    To copy to clipboard, switch view to plain text mode 

    my cpp:
    Qt Code:
    1. void myclass::contextMenuEvent(QContextMenuEvent *event)
    2. {
    3. if (event)
    4. {
    5. QMenu *menu = new QMenu;
    6. menu->addAction(new QAction("Action 1", this));
    7. menu->addAction(new QAction("Action 2", this));
    8. menu->addAction(new QAction("Action 3", this));
    9. menu->exec(event->globalPos());
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    It's work, but only with right click. And how to have this only on a QGraphicsItemGroup with a long left click ?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Context menu long left click on QGraphicsTextItem

    You can detect the pressEvent and then use a timer to measure the hold. If the timer fires before you detect a release you have a long-press. If the release happens before, you stop the timer.

    For a QGraphicsObject subclass you could also try QGraphicsObject::grabGesture()

    Cheers,
    _

Similar Threads

  1. Replies: 6
    Last Post: 20th July 2012, 23:50
  2. Replies: 7
    Last Post: 26th April 2012, 15:45
  3. Replies: 2
    Last Post: 3rd May 2011, 22:01
  4. cancle right click context menu in qtwebkit
    By umen in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2009, 22:06
  5. QWT right click window.. (Context Menu)
    By maveric in forum Qt Programming
    Replies: 4
    Last Post: 25th May 2008, 09:07

Tags for this Thread

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.