Results 1 to 8 of 8

Thread: QGraphicsScene and QGraphicsView

  1. #1
    Join Date
    Jul 2007
    Posts
    166
    Thanks
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QGraphicsScene and QGraphicsView

    Hi,

    I am using QT 4.2.2. I create a main winodw and in that window I place a tabwidget using QT designer and make the programe and it is working. I need a QGraphicsScence and a QGraphicsView. So add the following code in constructer after the
    " setupUi(this); // this sets up GUI "
    and Qt create the output.

    My problum is that, when I change the tab or QTabWidget then, the QGraphicsView display on the screen. I need that view on the first tab of my QTabWidget. How can I do that?. And also I need to change the line color as red.

    Please help me.....

    code:
    -----------------------

    QGraphicsScene *scene1 = new QGraphicsScene(this);
    QGraphicsView *view1 = new QGraphicsView(this);
    scene1 = new QGraphicsScene(0,0,65,457);
    view1->setScene(scene1);
    view1->setGeometry(QRect(716, 118, 70, 462));

    int x1, y1, x2, y2, t;
    x1 = 0; y1=0; x2=100; y2=2, t=0;
    //scene->setForegroundBrush(QColor(5, 25, 255, 127));
    //scene->setBackgroundBrush(QColor(5, 25, 255, 127));
    //QGraphicsLineItem *line = new QGraphicsLineItem( QLineF( 0,0, 100, 2 ) );
    QGraphicsLineItem *line;// = new QGraphicsLineItem( QLineF( 0,0, 100, 2 ) );
    for ( int a=0; a<100; a++) {
    QGraphicsLineItem *line = new QGraphicsLineItem( QLineF( x1,y1, x2, y2 ) );
    scene4->addItem(line);
    t=x1; x1=x2; x2 = t;
    y1= y2; y2= y2+6;
    }

    --------------------------------------------------------------------

    Sabeesh

  2. #2
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsScene and QGraphicsView

    Replace tabWidget->addTab(view) with tabWidget->insertTab(0,view); to make the view appear in first tab.

    To set red color for line use line->setPen(Qt::red)
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  3. #3
    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: QGraphicsScene and QGraphicsView

    First of all, you must add some layouts in the tab widgets.

    To answer your problem: start with an empty tab widget.
    Use QTabWidget::addTab(view1, "view1"); to create the first tab with the view in it.

    That is it.

    To change the line color:
    Qt Code:
    1. line->setPen(QPen(Qt::Red));
    To copy to clipboard, switch view to plain text mode 

    Regards

  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: QGraphicsScene and QGraphicsView

    Quote Originally Posted by Gopala Krishna View Post
    Replace tabWidget->addTab(view) with tabWidget->insertTab(0,view); to make the view appear in first tab.

    To set red color for line use line->setPen(Qt::red)
    Where does he call addTab?

  5. #5
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsScene and QGraphicsView

    Quote Originally Posted by marcel View Post
    Where does he call addTab?
    Yup you are right. I thought he was adding the view to the tabWidget in the designer itself. Anyway tabWidget->insertTab(0,view) will always insert the view in first tab.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  6. #6
    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: QGraphicsScene and QGraphicsView

    Quote Originally Posted by Gopala Krishna View Post
    Yup you are right. I thought he was adding the view to the tabWidget in the designer itself. Anyway tabWidget->insertTab(0,view) will always insert the view in first tab.
    Of course it will, but he has to remove those two default tabs added by designer, so addTab will work too.

    Regards

  7. #7
    Join Date
    Jul 2007
    Posts
    166
    Thanks
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: QGraphicsScene and QGraphicsView

    Hi,
    I can't solve my problem!!!!!!!!!!!!!
    The QTabWidget is designed using the Q.T.4.2.2 and add alos two tabs and these tabs hold some other widget. I want to add the new widget with these widget. Please help me....

    Sabeesh

  8. #8
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsScene and QGraphicsView

    Please go through this qt-designer-manual. This manual explains everything on how to access widgets.

    Also look at the documentation of QTabWidget.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 21:50
  2. QGraphicsScene / QGraphicsView speed after resize
    By themolecule in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2007, 00:46
  3. QGraphicsScene and QGraphicsView
    By rossd in forum Qt Programming
    Replies: 2
    Last Post: 25th April 2007, 15:43
  4. QGraphicsView and QGraphicsScene speeds
    By jnk5y in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2006, 08:13
  5. (QT4.2-RC1) QGraphicsScene QGraphicsView QGraphicsItem
    By antonio.r.tome in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 11:56

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.