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.
Code:
#ifndef _MAIN_H_
#define _MAIN_H_
#include <QGraphicsView>
{
Q_OBJECT;
public:
~View();
protected:
};
#endif
Code:
#include <QApplication>
#include <QMainWindow>
#include <QGraphicsScene>
#include <QGraphicsRectItem>
#include <QWheelEvent>
#include <QDebug>
#include <cmath>
#include "main.h"
/*----------------------------------------------------------------------------*/
{
setFrameStyle
( QFrame::NoFrame );
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
}
View::~View()
{
}
{
double numDegrees = event->delta() / 8.0;
double numSteps = numDegrees / 15.0;
double factor = std::pow(1.125, numSteps);
scale(factor, factor);
}
/*----------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
double dXMin = 2000000;
double dXWidth = 28000000;
double dYMin = 0.0;
double dYHeight = 86400.;
dXWidth, dYHeight );
View * pView = new View;
pView->setScene(pScene);
pView->fitInView( pScene->sceneRect() );
pWin->setCentralWidget(pView);
QRectF itemRect
( 0., 0., 4000., 5.
);
pItem->setPos( pView->sceneRect().center() );
pItem
->setCursor
(QCursor(Qt
::SizeAllCursor));
pScene->addItem( pItem );
pWin->show();
return app.exec();
}
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)?
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
[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.