Results 1 to 8 of 8

Thread: adding QGraphicsItem to multiple scenes

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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: adding QGraphicsItem to multiple scenes

    Quote Originally Posted by forrestfsu View Post
    So my problem has been, if I use only one scene and I add approx 20 QGraphicsItemGroup's to it. How can I make it so that I only show one of the QGraphicsItemGroup's in graphicsView2, using only 1 scene?
    I think you can use QGraphicsView::setSceneRect() to ask the view to only visualise a rectangle occupied by a single group.

  2. #2
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: adding QGraphicsItem to multiple scenes

    I've been attempting a different solution for part of my problem. Perhaps the following can work? To display the same QGraphicsItemGroup on different views with a different background, can I reimplement:

    QGraphicsView::drawBackground(QPainter *painter, const QRectF &rect)

    I was able to get it to display a background on all the views:
    Qt Code:
    1. void QGraphicsView::drawBackground(QPainter *painter, const QRectF &rect)
    2. {
    3. painter->drawEllipse(10, 10, 10, 10);
    4. }
    To copy to clipboard, switch view to plain text mode 
    However, I need to make it unique for each view. I want something like this:
    Qt Code:
    1. void QGraphicsView::drawBackground(QPainter *painter, const QRectF &rect)
    2. {
    3. if (this->ui.view1)
    4. painter->drawEllipse(10, 10, 10, 10);
    5. else if (this->ui.view2)
    6. painter->drawEllipse(20, 20, 20, 20);
    7. else if (this->ui.view3)
    8. painter->drawEllipse(30, 30, 30, 30);
    9. }
    To copy to clipboard, switch view to plain text mode 

    However, I can't seem to figure out how to code the if statement to recognize a specific graphics view on my form...any tips? I've tried:

    Qt Code:
    1. if (this->ui.view1)
    2. if (this->TheForm::ui.view1)
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: adding QGraphicsItem to multiple scenes

    Got it! This seems to work:

    Qt Code:
    1. if (this->objectName() == "view1")
    2. else if (this->objectName() == "view2")
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. how to corss compile for windows in Linux
    By safknw in forum Qt Programming
    Replies: 24
    Last Post: 13th May 2006, 05:23

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.