Results 1 to 6 of 6

Thread: multi-qgraphicsitem display help

  1. #1
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows

    Default multi-qgraphicsitem display help

    Sorry about the general-purpose title, was not sure how to exactly sum this up in a simple one-liner

    I am using QGraphicsView to display some pixmaps of data. Overlayed on top of these pixmaps are item data. Not sure if this matters, but there could be many. many of these items to display. This data can come from an outside source or from a user manually creating the item. The data will contain x,y positioning and width,height size information about the item to be displayed . . . so, a rectangular box. Internally the rect will be defined as -w/2.,0 w,h. Associated with this box will be another item, an icon, so to speak. I am ignoring transforms on the icon so I can draw the icon with a user defined size.

    The problem that I am having is that I want the icon to appear above the upper left corner or the box, if the box is visible . . . and the box is visible unless the user zooms far enough out that that the box is too small (level of detail < X). If the box is not visible, I want the icon to move to the top-centered location . . . which should be the original x,y position.

    extract.png

    Currently I am using a item group to hold the rect item and the shape (icon) item. I cannot find a way to trigger the move (setPos) of the icon based on the level of detail determined inside the paint method of the rect item.

    I was hoping that someone could point me in some direction to resolve this.
    Anything would be appreciated

  2. #2
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default Re: multi-qgraphicsitem display help

    I'm pretty certain you shouldn't be calling setPos inside the paint function, but rather you should be painting it differently, e.g., if it's big enough to see:

    Qt Code:
    1. painter->drawRect(rect.translated(someAmount, 0); // translate it to the left
    To copy to clipboard, switch view to plain text mode 

    otherwise:

    Qt Code:
    1. painter->drawRect(rect);
    To copy to clipboard, switch view to plain text mode 

    If you want more specific advice, it would be helpful to see your current paint function.

  3. #3
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: multi-qgraphicsitem display help

    The item group did not seem to work for me, so I moved to a parent-child relationship. The rect item is the parent with the icon item being the child. I seem to have better control of the icon since its "coordinate system" is based on the parent. I was wondering if it is okay to call setPos in the paint method of the parent to control the position of the child.

    Qt Code:
    1. void MyRectItem::paint( QPainter *painter,
    2. const QStyleOptionGraphicsItem *option,
    3. QWidget *widget )
    4. {
    5. Q_UNUSED(widget);
    6. Q_UNUSED(option);
    7. qreal lod = option->levelOfDetailFromTransform(painter->worldTransform());
    8. bool bShow = ( lod > 0.05 );
    9. if( bShow )
    10. {
    11. painter->setPen( pen() );
    12. painter->setBrush( brush() );
    13. painter->drawRect( rect() );
    14. }
    15.  
    16. if( bShow != m_bPainted && NULL != m_pIcon )
    17. {
    18. m_bPainted = bShow;
    19. // this seems to work okay, but is it "legal" to make this setPos call?
    20. m_pIcon->setPos( m_bPainted ? rect().topLeft() : QPointF( 0., 0. ) );
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

  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: multi-qgraphicsitem display help

    No, never do that.
    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. #5
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: multi-qgraphicsitem display help

    I am not happy with the "fix", but like I said, it seems to work . . . maybe is this simple isolated case.
    So what is a/the better solution to move this child.

  6. #6
    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: multi-qgraphicsitem display help

    To be honest, it is hard for me to understand the problem you have. An obvious solution seems to me to make the icon item a child of the main item and make it ignore transformations. When the main item becomes small as a result of scaling it (or the view) then at some point the physical coordinates of the icon item should match the physical coordinates of (currently very small) main item without doing anything special.
    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.


Similar Threads

  1. Replies: 7
    Last Post: 31st January 2012, 15:19
  2. Multi channel display with Qwt
    By jpo38 in forum Qwt
    Replies: 0
    Last Post: 11th October 2011, 07:44
  3. Display part of image on a smaller QGraphicsItem
    By biplab.project in forum Qt Programming
    Replies: 0
    Last Post: 5th January 2011, 10:03
  4. Multi line display
    By Percy in forum Qt Programming
    Replies: 1
    Last Post: 30th April 2010, 18:57
  5. Display a QWidget using multi-screen
    By tarod in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 14:02

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.