Results 1 to 4 of 4

Thread: qgraphicsrectitem "boundary" issue

  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 qgraphicsrectitem "boundary" issue

    I have created the following small program that demonstrates the problem that I am seeing in a much larger application.

    I am setting a oblong rectangle for a qgraphicsview to represent that data that I am expecting, but not sure if that has anything to do with it. I also have an item that is rather small when compared to the overall rectangle size. So with this example, you need to zoom in (wheel) quite a bit to get to a reasonable view of the small rectangle. Once the item is viewable you will notice that the cursor will change when it "enters" the item. However, the edge from the top of the box where the view/scene thinks the item starts is not at the edge of the item but several pixels away (higher). And gets worse as you zoom in.

    I am currently building this with 4.7.2 under Linux and do not have access to 4.8. Strange thing, if I build with 4.6.3, everything looks right. The edge of the item is actually at pixel edge of the item.

    Qt Code:
    1. #ifndef _MAIN_H_
    2. #define _MAIN_H_
    3.  
    4. #include <QGraphicsView>
    5.  
    6. class View : public QGraphicsView
    7. {
    8. Q_OBJECT;
    9.  
    10. public:
    11. View( QWidget* parent = 0 );
    12. ~View();
    13.  
    14. protected:
    15. void wheelEvent( QWheelEvent* event );
    16. };
    17.  
    18. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include <QApplication>
    2. #include <QMainWindow>
    3. #include <QGraphicsScene>
    4. #include <QGraphicsRectItem>
    5. #include <QWheelEvent>
    6. #include <QDebug>
    7. #include <cmath>
    8. #include "main.h"
    9.  
    10. /*----------------------------------------------------------------------------*/
    11.  
    12. View::View( QWidget* parent )
    13. : QGraphicsView( parent )
    14. {
    15. setFrameStyle( QFrame::NoFrame );
    16. setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    17. setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    18. }
    19.  
    20. View::~View()
    21. {
    22. }
    23.  
    24. void View::wheelEvent( QWheelEvent* event )
    25. {
    26. double numDegrees = event->delta() / 8.0;
    27. double numSteps = numDegrees / 15.0;
    28. double factor = std::pow(1.125, numSteps);
    29. scale(factor, factor);
    30. }
    31.  
    32. /*----------------------------------------------------------------------------*/
    33.  
    34. int main(int argc, char *argv[])
    35. {
    36. QApplication app(argc, argv);
    37. QMainWindow * pWin = new QMainWindow;
    38.  
    39. double dXMin = 2000000;
    40. double dXWidth = 28000000;
    41. double dYMin = 0.0;
    42. double dYHeight = 86400.;
    43.  
    44. QGraphicsScene * pScene = new QGraphicsScene( dXMin, dYMin,
    45. dXWidth, dYHeight );
    46.  
    47. View * pView = new View;
    48. pView->setScene(pScene);
    49. pView->fitInView( pScene->sceneRect() );
    50. pWin->setCentralWidget(pView);
    51.  
    52. QRectF itemRect( 0., 0., 4000., 5. );
    53. QGraphicsRectItem *pItem = new QGraphicsRectItem( itemRect );
    54. pItem->setPos( pView->sceneRect().center() );
    55. pItem->setCursor(QCursor(Qt::SizeAllCursor));
    56. pScene->addItem( pItem );
    57.  
    58. pWin->show();
    59. return app.exec();
    60. }
    To copy to clipboard, switch view to plain text mode 

  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: qgraphicsrectitem "boundary" issue

    Does the effect change if you scale all your values by the factor of say... 0.01 (so that itemRect becomes 0,0, 40, 0.05)?
    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
    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: qgraphicsrectitem "boundary" issue

    adjusting the rect item value by 0.01 (0,0,40,0.05) makes the edge problem worse . . . but again. 4.6.3 works fine
    Last edited by mcarter; 2nd April 2012 at 03:13.

  4. #4
    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 [SOLVED] qgraphicsrectitem "boundary" issue

    examining the Qt bugs, it looks like someone has finally fixed this in the latest Qt 4.8.1 release . . . fixed itemsAtPosition method in qgraphicsscene.cpp . . . using some of the 4.6 code. Currently not able to move to 4.8 base, so will stick with 4.6 for now.

Similar Threads

  1. Replies: 2
    Last Post: 14th November 2010, 11:14
  2. Loading plugin and "Incompatible Qt library" issue.
    By TorAn in forum Qt Programming
    Replies: 4
    Last Post: 31st May 2010, 13:04
  3. Replies: 2
    Last Post: 6th October 2009, 01:09
  4. QSystemTrayIcon as "main window" design issue
    By nooky59 in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2008, 13:15
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

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.