Results 1 to 3 of 3

Thread: Graphics View context Menu...

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    40
    Thanked 8 Times in 4 Posts

    Default Graphics View context Menu...

    Hi guys,

    I have created a graphics view in the designer. I also have a class that works with implementing some solutions for the view. So I create the class object(giving the ui.GraphicsView using refrence -> so the class could change it).
    But when I try to set context Menu for the Scene(which is also a member of that class -> add to the graphicsView in the constructor) or the GraphicsView It doesn not show.
    I have implemented it for the main window and it worked, but When I try to use context menu for the view it does not show. Maybe there is a problem with passing the ui.GraphicsView(created in the Designer) as a reference and then creating it's context menu? Yet I am looking for a solution. Maybe someone had this kind of dilema.

    Beforehand thanks!

    Maverick

    P.S.

    Passing the ui.GraphicsView as a reference should do the job, but doesn not work. Or maybe the problem is somewhere else. ANy hints appreciated.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

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

    Default Re: Graphics View context Menu...

    Could we see the relevant code?
    J-P Nurmi

  3. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    40
    Thanked 8 Times in 4 Posts

    Default Re: Graphics View context Menu...

    I am bit busy right now, but will post the code soon.

    I have created, using designer, a graphics view -> ui.gvChart
    I also have a class containing m_scene and m_view:
    Qt Code:
    1. class Chart: public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public :
    6. Chart(QGraphicsView*,QWidget* parent = 0);
    7. ~Chart();
    8.  
    9. View* m_view;
    10. QGraphicsScene* m_scene;
    11. ..........
    12. }
    13. Chart::Chart( QGraphicsView* v,QWidget* parent): QWidget(parent)
    14. {
    15. m_view = dynamic_cast<View*>(v);
    16. vSetScene();
    17. vSetView();
    18. }
    19. void Chart::vSetView()
    20. {
    21. m_view->setScene(m_scene);
    22. m_view->show();
    23. //setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    24. }
    25.  
    26. void Chart::vSetScene()
    27. {
    28. m_scene = new QGraphicsScene(this);
    29. m_scene->setItemIndexMethod(QGraphicsScene::BspTreeIndex);
    30. m_scene->setSceneRect(0, 0, m_view->width(),m_view->height());
    31. m_scene->setBackgroundBrush(QBrush(Qt::gray));
    32. }
    To copy to clipboard, switch view to plain text mode 

    Here is the View class:
    Qt Code:
    1. class View: public QGraphicsView
    2. {
    3. public:
    4. View(QWidget* parent): QGraphicsView(parent) {}
    5. ~View() {}
    6.  
    7. protected:
    8. void contextMenuEvent(QContextMenuEvent*);
    9. };
    10. void View::contextMenuEvent(QContextMenuEvent* event)
    11. {
    12. QMenu* m_contextMenu;
    13. m_contextMenu = new QMenu;
    14. QAction* act = new QAction(QIcon(""),tr("Buuuuu"),this);
    15. m_contextMenu = new QMenu;
    16. m_contextMenu->addAction(act);
    17. m_contextMenu->exec(event->globalPos());
    18. }
    To copy to clipboard, switch view to plain text mode 

    In the main class I create the Chart class:
    Qt Code:
    1. m_chart = new Chart(ui.gvChart,this);
    To copy to clipboard, switch view to plain text mode 

    That's about all. I have added contextMenu code(used here) to show main Window context menu and the context Menu appears, but not workin here.

    Thanks in advance for help.

    Maverick

    P.S.
    the code compiles, but crashes in the SetScene(...->setSceneRect);
    Last edited by maverick_pol; 8th May 2007 at 11:22.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

Similar Threads

  1. Context Menu on QTableWidget
    By ankurjain in forum Qt Programming
    Replies: 9
    Last Post: 17th December 2009, 10:52
  2. Misplaced Context Menu
    By kandalf in forum Qt Programming
    Replies: 6
    Last Post: 18th February 2007, 05:28
  3. graphics view FitInView problem
    By aamer4yu in forum Qt Programming
    Replies: 6
    Last Post: 25th January 2007, 11:24
  4. Adding Rectangular overlay on graphics view
    By forrestfsu in forum Qt Programming
    Replies: 10
    Last Post: 21st November 2006, 20:42
  5. Q3TextEdit custom context menu
    By bcteh_98 in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 22:00

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.