There are times I find C++ to be a deeply annoying language.
I have a class, lets call it A, and within that class definition I have the following:
private:
static QPainterPath *path;Which is to say, I'm declaring a static (class-wide) pointer to a path object; all instances of this class will now have the same shared data member. The path object
(
Read more... )
Comments 4
Reply
void A::paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget)
{
painter->setPen(*this->pen);
painter->drawPath(*this->path);
}
And yes, I could duplicate that in every subclass I write, and duplicate the similarly small functions to return the shape and bounding rect of the item, but then there would be very little need for the base class and I might as well just copy/paste the whole class each time I want a varient on it instead of subclassing.
Reply
QPainterPath* A::getPath()
{
return A::path;
}
And the same little stub functions for your base classes, and then change your paint and bounding rect and all those functions to use getPath() to get hold of the path?
Reply
The thread can be found here.
Reply
Leave a comment