nilot
29th June 2017, 13:59
Hello,
I have a black rectangle whose coordinates are (90,90) , (90,100), (150, 100) and (150, 90) drawn on a white background ( see test_6.png) 12505
I use this image as a background image on my qgraphicsScene.
I want to draw a red QGraphicsRectItem that overlaps perfectly the black rectangle.
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsRectItem>
#include <QPen>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsScene scene;
QGraphicsRectItem* item = new QGraphicsRectItem(QRectF(90,90,60, 10));
QPen pen = QPen(Qt::red, 1, Qt::SolidLine);
pen.setCosmetic(true);
item->setBrush(QColor(255, 0, 0));
item->setPen(pen);
scene.addItem(item);
QPixmap image = QPixmap("path_to_image");
scene.setSceneRect(image.rect());
QGraphicsView view(&scene);
view.setBackgroundBrush(QBrush(image));
view.show();
view.scale(3,3); // in order to see the problem
return a.exec();
}
However I notice a small difference of one pixel at the right and at the bottom of my QGraphicsItem : indeed I shouldn't see any black pixel if the overlap was perfect ( see 12504)
Do you understand why there is such a problem ?
Thank you
I have a black rectangle whose coordinates are (90,90) , (90,100), (150, 100) and (150, 90) drawn on a white background ( see test_6.png) 12505
I use this image as a background image on my qgraphicsScene.
I want to draw a red QGraphicsRectItem that overlaps perfectly the black rectangle.
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsRectItem>
#include <QPen>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsScene scene;
QGraphicsRectItem* item = new QGraphicsRectItem(QRectF(90,90,60, 10));
QPen pen = QPen(Qt::red, 1, Qt::SolidLine);
pen.setCosmetic(true);
item->setBrush(QColor(255, 0, 0));
item->setPen(pen);
scene.addItem(item);
QPixmap image = QPixmap("path_to_image");
scene.setSceneRect(image.rect());
QGraphicsView view(&scene);
view.setBackgroundBrush(QBrush(image));
view.show();
view.scale(3,3); // in order to see the problem
return a.exec();
}
However I notice a small difference of one pixel at the right and at the bottom of my QGraphicsItem : indeed I shouldn't see any black pixel if the overlap was perfect ( see 12504)
Do you understand why there is such a problem ?
Thank you