Results 1 to 3 of 3

Thread: Adding events to GraphicsView created with designer

  1. #1
    Join Date
    Oct 2007
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Adding events to GraphicsView created with designer

    I work with qtcreator to make qt apps.
    I want to add mouseReleaseEvent to graphicsView created already with designer.

    Here is my subclass

    Qt Code:
    1. class MyView : public QGraphicsView {
    2. Q_OBJECT
    3. public:
    4. MyView(QGraphicsView *graphicsView_skel, QWidget *parent = 0);
    5. protected:
    6. void mouseReleaseEvent(QMouseEvent *event);
    7. private slots:
    8. private:
    9. };
    To copy to clipboard, switch view to plain text mode 

    Here is the code for creating scene on view and adding items

    Qt Code:
    1. MyView::MyView(QGraphicsView *view_skel,QWidget *parent) : QGraphicsView(parent)
    2.  
    3. {
    4. scene = new QGraphicsScene(view_skel);
    5. scene->setSceneRect(0, 0, 250, 500);
    6. view_skel->setScene(scene);
    7. ImageItem *image;
    8. image = new ImageItem(1, QPixmap("icons/skel2.png"));
    9. image->setData(0, 0);
    10. image->setPos(30, 100);
    11. scene->addItem(image);
    12. }
    To copy to clipboard, switch view to plain text mode 

    I call it from
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent), ui(new Ui::MainWindowClass)
    3.  
    4. {
    5. ui->setupUi(this);
    6. MyView(ui->graphicsView_skel);
    7. }
    To copy to clipboard, switch view to plain text mode 

    Everything is ok but mouse relase event doesnt work

    Qt Code:
    1. void MyView::mouseReleaseEvent(QMouseEvent *event)
    2. {
    3. printf("Mouse released\n");
    4. QGraphicsView::mouseReleaseEvent(event);
    5. }
    To copy to clipboard, switch view to plain text mode 


    Can anyone help me?
    Last edited by mkarakaplan; 3rd May 2009 at 22:22.

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding events to GraphicsView created with designer

    replace the virtual function ..
    QGraphicsView:mouseReleaseEvent(QMouseEvent *event)
    with ....
    QGraphicsView ::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)

  3. #3
    Join Date
    Oct 2007
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Adding events to GraphicsView created with designer

    Quote Originally Posted by wagmare View Post
    replace the virtual function ..
    QGraphicsView:mouseReleaseEvent(QMouseEvent *event)
    with ....
    QGraphicsView ::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
    Didnt worked. I am writing all project again without qtdesigner.
    Thanks.

Similar Threads

  1. Overiding QGraphicsView events with Designer
    By dbrmik in forum Qt Tools
    Replies: 2
    Last Post: 26th July 2011, 08:34
  2. Adding events to GraphicsView
    By mkarakaplan in forum Qt Programming
    Replies: 6
    Last Post: 4th May 2009, 00:26
  3. Adding scrollbars from within Designer
    By MrGarbage in forum Qt Tools
    Replies: 1
    Last Post: 3rd September 2007, 19:35
  4. changing QLabel font size(label created on the graphicsView)
    By maverick_pol in forum Qt Programming
    Replies: 11
    Last Post: 17th August 2007, 08:36
  5. Adding slots in Designer
    By jamos in forum Qt Tools
    Replies: 5
    Last Post: 18th May 2006, 23:28

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.