Results 1 to 20 of 20

Thread: Add Static area to QGraphicsView

  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 Add Static area to QGraphicsView

    I am in the process of making a tvguide. I have used a QGraphicsView and added QGraphicsItems with the program name. I would like to add static areas, one on the left to display the channel name, icon and one at the top to display a timebar.

    could you suggest a method of achieving this?

    the ui has been draw using QTCreator, not hand coded. I have looked at setViewPortMargins but i dont how i would use this with the standard QGraphicsView from Creator.

    Any help or guidance much appreciated.


  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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

    There are many ways to do that. One would indeed be to use viewport margins, another would be to put one view over another one. You could also simply use regular items and move them to appropriate positions when the view is scrolled.
    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.


  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

    Thanks for your reply. in your opinion what would be the 'best' approach?

    I looked at drawing regular shapes over the view and moving them as the view moves, therefore, them seeming to stay in the same position. I couldn't workout how to collect a signal from the view to indicate that it had moved.

    could you advise?

    Thanks,

    Dubstar_04

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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
    Thanks for your reply. in your opinion what would be the 'best' approach?
    It's not possible to say what's best until you try something. I don't know your specific use-case.
    I couldn't workout how to collect a signal from the view to indicate that it had moved.
    The view has scroll bars that emit a valueChanged() signal.
    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.


  5. The following user says thank you to wysota 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

    i have been looking at this and i dont know how to collect the valueChanged() signal.

    i tried:

    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 

    and there is no signal available there.

    I have also tried this(with no result):

    Qt Code:
    1. QAbstractSlider *verticalSlider = new QAbstractSlider(ui->graphicsView->verticalScrollBar());
    2.  
    3. connect(verticalSlider, SIGNAL(sliderMoved(int)), SLOT(warning(int value)) );
    To copy to clipboard, switch view to plain text mode 
    Last edited by dubstar_04; 13th April 2011 at 14:59.

  7. #6
    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

    can anyone direct me how to connect the valueChanged() signal of the the scrollBar to a slot?

    I have tried everything i can think of.

    The last thing i have tried is subclassing QGraphicsView and calling the connect from there but the signal is unavailable.

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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

    How did you implement warning()? Does connect() return true?
    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.


  9. #8
    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.

  10. #9
    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.

  11. #10
    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 

  12. #11
    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 ?

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

    dubstar_04 (14th April 2011)

  14. #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

    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

  15. #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

    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).

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

    dubstar_04 (14th April 2011)

  17. #14
    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.

  18. #15
    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 ?

  19. #16
    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.

  20. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.


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

    dubstar_04 (14th April 2011)

  22. #18
    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.

  23. #19
    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

  24. #20
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.