Results 1 to 12 of 12

Thread: Subclassing QGraphicsView

  1. #1
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Subclassing QGraphicsView

    Here is my iadfuqgraphicsview.h. I encounter errors such as

    iadfuqgraphicsview.h:13: error: expected unqualified-id at end of input
    iadfuqgraphicsview.h:13: error: expected `,' or `;' at end of input

    How can I solve this?

    Qt Code:
    1. #ifndef IADFUQGraphicsView_H
    2. #define IADFUQGraphicsView_H
    3.  
    4. #include <QtGui>
    5. #include <QObject>
    6.  
    7. class IADFUQGraphicsView : public QGraphicsView
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. IADFUQGraphicsView(QGraphicsScene* s);
    13. ~IADFUQGraphicsView(){} ;
    14.  
    15. protected:
    16. void contextMenuEvent(QContextMenuEvent *event);
    17. void mousePressEvent( QMouseEvent* e );
    18.  
    19. private:
    20. QPointF* m_clickedPt;
    21. QGraphicsPixmapItem* m_pixmapItem;
    22. QGraphicsScene* m_scene;
    23.  
    24. QAction *cutAct;
    25. QAction *copyAct;
    26. QAction *pasteAct;
    27.  
    28. }
    29.  
    30. #endif
    To copy to clipboard, switch view to plain text mode 

    Also, How can I create an iadfuqgraphicsview.cpp that properly overrides the contextMenuEvent and mousePressEvent methods of QGraphicsView? Can anybody create a code for that?
    Image Analysis Development Framework Using Qt (IADFUQ)

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

    Default Re: Subclassing QGraphicsView

    Quote Originally Posted by sincnarf View Post
    I encounter errors such as

    iadfuqgraphicsview.h:13: error: expected unqualified-id at end of input
    iadfuqgraphicsview.h:13: error: expected `,' or `;' at end of input
    You're missing a semi-colon (";") at the end of the class declaration:
    Qt Code:
    1. class Blaa
    2. {
    3. }; // <---
    To copy to clipboard, switch view to plain text mode 

    Also, How can I create an iadfuqgraphicsview.cpp that properly overrides the contextMenuEvent and mousePressEvent methods of QGraphicsView? Can anybody create a code for that?
    Take a look at the Elastic Nodes Example. GraphWidget inherits QGraphicsView and reimplements a few event handlers. You can do it the same way.
    J-P Nurmi

  3. #3
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QGraphicsView

    Thanks but my problem is I need to use the constructor of the QGraphicsView that accepts QWidget as a parameter... how can I do that? also where is the proper place to place that constructor? in .cpp or .h ?
    Image Analysis Development Framework Using Qt (IADFUQ)

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QGraphicsView

    The proper way is to declare it in the header and define(implement) it in the cpp.
    Qt Code:
    1. //in the header
    2. class CustomView:public QGraphicsView
    3. {
    4. public:
    5. CustomView(QGraphicsScene*, QWidget*=NULL);
    6. ~CustomView();
    7. };
    8.  
    9. //in the cpp
    10. CustomView::CustomView(QGraphicsScene *scene, QWidget* parent)
    11. :QGraphicsView(scene, parent)
    12. {
    13. //...
    14. }
    To copy to clipboard, switch view to plain text mode 
    Regards

  5. The following user says thank you to marcel for this useful post:

    sincnarf (27th August 2007)

  6. #5
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QGraphicsView

    I have compilation problems using your recommended consctructor

    This is my iadfuqgraphicsview.cpp file
    Qt Code:
    1. #include "iadfuqgraphicsview.h"
    2.  
    3. IADFUQGraphicsView::IADFUQGraphicsView(QGraphicsScene *scene, QWidget* parent) :QGraphicsView(scene, parent)
    4. {
    5. }
    To copy to clipboard, switch view to plain text mode 

    and this is my iadfuqgrahicsview.h file
    Qt Code:
    1. #ifndef IADFUQGRAPHICSVIEW_H
    2. #define IADFUQGRAPHICSVIEW_H
    3.  
    4. #include <QtGui>
    5.  
    6. class QObject;
    7. class QWidget;
    8.  
    9. class IADFUQGraphicsView : public QGraphicsView
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. IADFUQGraphicsView(QGraphicsScene*, QWidget*= NULL);
    15. ~IADFUQGraphicsView();
    16. };
    To copy to clipboard, switch view to plain text mode 

    my errors are as follows:
    error: prototype for `IADFUQGraphicsView::IADFUQGraphicsView(QGraphicsS cene*, QWidget*)' does not match any in class `IADFUQGraphicsView'

    error: candidates are: IADFUQGraphicsView::IADFUQGraphicsView(const IADFUQGraphicsView&)
    Image Analysis Development Framework Using Qt (IADFUQ)

  7. #6
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QGraphicsView

    o m g. Can't figure this out. Sorry for my simple mistakes in C. I'm more inclined to 'other' programming languages than C and C++.
    Image Analysis Development Framework Using Qt (IADFUQ)

  8. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QGraphicsView

    Well, first of all, don't include QtGui in the header. Do it in the cpp.
    Include only QGraphicsView and keep the forward declarations.

    And are those all your sources? Could you post the complete ones?

  9. #8
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QGraphicsView

    Using your previous tips I got compilation errors that says
    iadfuqgraphicsview.h:14: error: expected `,' or `...' before '*=' token
    iadfuqgraphicsview.cpp:4: error: prototype for `IADFUQGraphicsView::IADFUQGraphicsView(QGraphicsS cene*, QWidget*)' does not match any in class `IADFUQGraphicsView'
    iadfuqgraphicsview.h:10: error: candidates are: IADFUQGraphicsView::IADFUQGraphicsView(const IADFUQGraphicsView&)
    iadfuqgraphicsview.h:14: error: IADFUQGraphicsView::IADFUQGraphicsView(QGraphicsSc ene*, QWidget)

    iadfuqgraphicsview.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include "iadfuqgraphicsview.h"
    3. IADFUQGraphicsView::IADFUQGraphicsView(QGraphicsScene *scene, QWidget* parent) :QGraphicsView(scene, parent)
    4. {
    5. }
    To copy to clipboard, switch view to plain text mode 

    complete header code
    Qt Code:
    1. #ifndef IADFUQGRAPHICSVIEW_H
    2. #define IADFUQGRAPHICSVIEW_H
    3.  
    4. class QObject;
    5. class QWidget;
    6.  
    7. class IADFUQGraphicsView : public QGraphicsView
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. IADFUQGraphicsView(QGraphicsScene*, QWidget*= NULL);
    13. ~IADFUQGraphicsView();
    14. };
    15.  
    16. #endif
    To copy to clipboard, switch view to plain text mode 
    Last edited by sincnarf; 27th August 2007 at 18:53. Reason: insufficient error report
    Image Analysis Development Framework Using Qt (IADFUQ)

  10. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QGraphicsView

    But I told you to include QGraphicsView in the header.

  11. #10
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QGraphicsView

    same error. sorry kind of sleepy here.

    I tried to place
    #include <QtGui/QGraphicsView>

    also tried to place
    #include <QGraphicsView>

    also tried the forward declaration
    class QGraphicsView;

    still got the same error as before
    iadfuqgraphicsview.h:16: error: expected `,' or `...' before '*=' token
    iadfuqgraphicsview.cpp:4: error: prototype for `IADFUQGraphicsView::IADFUQGraphicsView(QGraphicsS cene*, QWidget*)' does not match any in class `IADFUQGraphicsView'
    iadfuqgraphicsview.h:12: error: candidates are: IADFUQGraphicsView::IADFUQGraphicsView(const IADFUQGraphicsView&)
    iadfuqgraphicsview.h:16: error: IADFUQGraphicsView::IADFUQGraphicsView(QGraphicsSc ene*, QWidget)
    Image Analysis Development Framework Using Qt (IADFUQ)

  12. #11
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QGraphicsView

    Try this:

    the header(customgv.h):
    Qt Code:
    1. #ifndef CUSTOMGV_H
    2. #define CUSTOMGV_H
    3.  
    4. #include <QGraphicsView>
    5.  
    6. class QWidget;
    7.  
    8. class customgv : public QGraphicsView
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. customgv(QGraphicsScene*, QWidget*= NULL);
    14. ~customgv();
    15. };
    16. #endif
    To copy to clipboard, switch view to plain text mode 

    the cpp(customgv.cpp):
    Qt Code:
    1. #include <QtGui>
    2. #include "customgv.h"
    3. customgv::customgv(QGraphicsScene *scene, QWidget* parent) :QGraphicsView(scene, parent)
    4. {
    5. }
    To copy to clipboard, switch view to plain text mode 

    You might have another class named IADF...

    Regards

  13. The following user says thank you to marcel for this useful post:

    sincnarf (27th August 2007)

  14. #12
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QGraphicsView

    What the.. this worked. Now trying to override contextMenuEvent and mousePressEvent s
    Image Analysis Development Framework Using Qt (IADFUQ)

Similar Threads

  1. QGraphicsView
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 26th July 2007, 08:00
  2. Speed, transparency, and drop issues with QGraphicsView
    By jefferai in forum Qt Programming
    Replies: 16
    Last Post: 30th June 2007, 16:14
  3. no image displayed on QGraphicsView
    By sincnarf in forum Qt Programming
    Replies: 9
    Last Post: 28th June 2007, 12:33
  4. QGraphicsView and item focus
    By Micawber in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2007, 20:36
  5. Using QGraphicsView with model/view programming
    By JLP in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 11:04

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.