QGraphicsItem::shape
-
I am unable to reproduce this problem with the example below. Does my example reproduce the problem for you? If not, can you modify it so that it does? Which version of Qt are you using and on which platform?
@
#include <QtGui>class GraphicsItem : public QGraphicsPixmapItem
{public:
GraphicsItem()
{
QPixmap pix("logo.png");
setFlags(flags() | QGraphicsItem::ItemClipsToShape);
setPixmap(pix);
}
QPainterPath shape () const
{
QPainterPath p;
p.addEllipse(0, 0, 50, 50);
return p;
}};
class GraphicsView : public QGraphicsView
{
Q_OBJECT
public:
GraphicsView()
{
QGraphicsScene *myScene = new QGraphicsScene(this);
setScene(myScene);
GraphicsItem *myItem = new GraphicsItem();
myScene->addItem(myItem);
setRenderHint(QPainter::Antialiasing);}
};
#include "main.moc"
int main(int argc, char** argv)
{
QApplication app(argc, argv);
GraphicsView window;
window.show();
return app.exec();}
@ -
hi sigrid.
i finally managed to change your code to show the same problem.
@#include <QtGui>
class GraphicsItemParent :public QGraphicsItem {
public:
GraphicsItemParent() {
setFlag(ItemClipsChildrenToShape);
}QRectF boundingRect() const { return QRectF(0, 0, 200, 200); } void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { painter->setPen(Qt::black); painter->drawRect(boundingRect()); }
};
class GraphicsItem : public QGraphicsItem
{public:
GraphicsItem(QColor c, QGraphicsItem* parent = 0):QGraphicsItem(parent)
{
setFlags(flags() | QGraphicsItem::ItemClipsToShape);
setFlag(ItemIsMovable);
color = c;
}QRectF boundingRect() const {
return QRectF(0,0, 100, 100);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
painter->setRenderHint(QPainter::Antialiasing);
painter->fillPath(shape(), color);
}QPainterPath shape () const
{
QPainterPath p;
p.addEllipse(50, 50, 50, 50);
return p;
}
QColor color;
};
class GraphicsView : public QGraphicsView
{
Q_OBJECT
public:
GraphicsView()
{
QGraphicsScene myScene = new QGraphicsScene(this);
setScene(myScene);
GraphicsItemParent parent = new GraphicsItemParent();
myScene->addItem(parent);
GraphicsItem *myItem1 = new GraphicsItem(Qt::red, parent);
GraphicsItem *myItem2 = new GraphicsItem(Qt::green, parent);
myItem1->setPos(50, 50);
myItem2->setRotation(15);
setSceneRect(0, 0, 100, 100);
scale(3, 3);
setRenderHint(QPainter::Antialiasing);}
};
#include "main.moc"
int main(int argc, char** argv)
{
QApplication app(argc, argv);
GraphicsView window;
window.show();
return app.exec();}@
as you can see, i only changed to draw a colored circle instead of an image (same behavior with image). as well as i added a parent item.
now the both circles are jagged, as well as the green circle is clipped to the parents shape with jags because of its rotation.
What is the best work around to get it painted probably?
thanks
Nazgul
-
I'm using Qt 4.7.4 on Mac. I currently don't have a windows machine to test it there.
Here is the screen:
!http://www.image-load.net/users/public/images/IzBG3bbCdy.png(screenshot)!
-
ok, i now tried with Qt 4.7.3 on Mac and got the same results as with qt 4.7.4.
then i tried on a windows machine (Windows Vista) also with qt 4.7.3 .
On windows there was a regular clipping like intended. no jags at all, like you experienced too.
is it a Qt Bug?
-
This sounds like a Qt bug, I suggest you report it in "Jira":https://bugreports.qt.nokia.com//secure/Dashboard.jspa and include the example that reproduces the problem and the screenshots as well.