Results 1 to 20 of 20

Thread: Add Static area to QGraphicsView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Add Static area to QGraphicsView

    warning() is just a slot that prints the int value via std::cout.

    Qt Code:
    1. connect(ui->graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)),this, SLOT(warning(int value)));
    To copy to clipboard, switch view to plain text mode 

    wont compile:



    I dont know how to connect the ui->graphicsView->verticalScrollBar() to the slot or even if thats the correct object to connect.

    Thanks,

    Dubstar_04
    Last edited by dubstar_04; 13th April 2011 at 16:53.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Add Static area to QGraphicsView

    Qt Code:
    1. connect(ui->graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)),this, SLOT(warning(int /*no parameter name here*/ )));
    To copy to clipboard, switch view to plain text mode 
    You can't give parameter name in SIGNAL or SLOT macro, only types.

  3. #3
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Add Static area to QGraphicsView

    I added a screenshot of the build error. error is still the same with:

    Qt Code:
    1. connect(ui->graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)),this, SLOT(warning(int)));
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Add Static area to QGraphicsView

    I added a screenshot of the build error. error is still the same
    Ok, I haven't seen the error before posting.
    Maybe it's a stupid question, but - is the MainWindow a subclass of QObject (QWidget,QMainWindow,...) ? Does this class have Q_OBJECT macro in private section ?
    QScrollBar is QObject-based for sure. Can you show the class header ?

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

    dubstar_04 (14th April 2011)

  6. #5
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Add Static area to QGraphicsView

    This is the MainWindow class header.

    Normally when i am typing the connections, QTCreator offers a list of signals that can be emitted by the object. when i am typing this connection in nothing is offered.

    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. QNetworkAccessManager manager2;
    6. QList<QNetworkReply *> currentDownloads;
    7.  
    8. public:
    9. explicit MainWindow(QWidget *parent = 0);
    10. ~MainWindow();
    To copy to clipboard, switch view to plain text mode 

    Thanks,

    Dubstar_04

  7. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Add Static area to QGraphicsView

    This is the MainWindow class header.
    Well, I can agree that this could be a part of MainWindow class header

    There should be nothing wrong in your code, my quick test looks very similar and works:
    Qt Code:
    1. // test.h
    2. #include <QtGui>
    3.  
    4. class MainW : public QMainWindow{
    5. Q_OBJECT
    6.  
    7. QGraphicsView * view;
    8.  
    9. public:
    10. explicit MainW( QWidget * parent = NULL );
    11. public slots:
    12. void warning( int value ){
    13. this->setWindowTitle(QString::number(value));
    14. }
    15. };
    16.  
    17. // test.cpp
    18. #include "test.h"
    19.  
    20. MainW::MainW( QWidget * parent ) : QMainWindow(parent){
    21. view = new QGraphicsView(this);
    22. QGraphicsScene * scene = new QGraphicsScene(this);
    23. scene->setSceneRect(0,0,1000,1000);
    24. view->setScene(scene);
    25. this->setCentralWidget(view);
    26. connect( view->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(warning(int)) );
    27. }
    28.  
    29. int main(int argc, char *argv[]){
    30. QApplication a(argc, argv);
    31. MainW m;
    32. m.show();
    33. return a.exec();
    34. }
    To copy to clipboard, switch view to plain text mode 

    Try to make a clean build ( make clean, qmake, make ). If this doesn't help, post full code (if you can).

  8. The following user says thank you to stampede for this useful post:

    dubstar_04 (14th April 2011)

  9. #7
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Add Static area to QGraphicsView

    stampede,

    I just made a new project and copied your example and i get the same error.

    if i edit out the connect line it builds and runs as expected?

    am using QT 4.7 on a mac.

    any further suggestions?

    Thanks,

    Dubstar_04
    Last edited by dubstar_04; 13th April 2011 at 19:11.

  10. #8
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Add Static area to QGraphicsView

    That's really weird, I'm sorry but I can't help you more, because my experience with mac == 0
    I see that you have Unix and Windows in your profile info, does all of this works on those systems, can you check that ?

  11. #9
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Add Static area to QGraphicsView

    i am just uninstalling all the Qt stuff off my mac as i have loads of different versions. I will try and build it again once i have reinstalled everything.

    I will try the linux and windows machines if that doesnt work.

    Thanks for all your help.

    update:
    Reinstalled qt on mac. same error.
    it wouldnt build on linux either. same issue.
    Last edited by dubstar_04; 13th April 2011 at 19:12.

  12. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Add Static area to QGraphicsView

    Quote Originally Posted by dubstar_04 View Post
    I added a screenshot of the build error. error is still the same with:

    Qt Code:
    1. connect(ui->graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)),this, SLOT(warning(int)));
    To copy to clipboard, switch view to plain text mode 
    This usually means you forgot to #include <QScrollBar> or "mainwindow.h" and your compiler doesn't know QScrollBar or MainWindow are subclasses of QObject.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    dubstar_04 (14th April 2011)

  14. #11
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Add Static area to QGraphicsView

    Wysota,

    Thanks for your reply. I thought i had included <QScrollBar>.

    I will have a look later as i am back in work today

    I wish i was a professional developer. its so interesting.

  15. #12
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Add Static area to QGraphicsView

    SUCCESS !!!!

    it was just missing a <QScrollBar> include.

    I cant thank you guys enough for the help.

    I have now drawn the timebar over the guide and it works beautifully!!

    Thanks,

    Dubstar_04

  16. #13
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Add Static area to QGraphicsView

    I don't understand something, dubstar_04 said that he couldn't compile my example with Qt 4.7, and that #include <QScrollBar> helped. But doesn't #include <QtGui> including all QtGui module classes definitions ? That's what documentation states:
    To include the definitions of both modules' classes, use the following directive:
    #include <QtGui>
    It works without including separate header for QScrollBar on my side (Qt 4.5.2 on windows xp and Qt 4.7.2 on Ubuntu 9.02).

Similar Threads

  1. Replies: 8
    Last Post: 5th April 2011, 10:19
  2. static sight on QGraphicsView
    By thgis in forum Qt Programming
    Replies: 0
    Last Post: 7th October 2010, 08:55
  3. Replies: 1
    Last Post: 9th December 2009, 08:44
  4. Putting static controls on top of QGraphicsView
    By durbrak in forum Qt Programming
    Replies: 3
    Last Post: 10th September 2007, 12:51
  5. Replies: 4
    Last Post: 14th February 2006, 21:35

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.