Hi,
Thanks for the help - yes, I had a look at the source of QStyleOption and QSizeGrip... In QStyleOption the init() method gets the different style settings from a widget (rect, direction, font metrics etc.). I also tried adding the QWidget as base class to MyRectangle, but it didn't change anything...
{
opt.corner = Qt::BottomLeftCorner;
opt.rect = boundingRect().toRect();
opt.state = option->state;
pen.setStyle(Qt::SolidLine);
pen.
setColor(QColor(Qt
::black));
pen.setWidth(1);
if(option
->state
& QStyle::State_Selected) {
pen.setStyle(Qt::DashLine);
pen.
setColor(QColor(Qt
::green));
}
painter->setPen(pen);
painter->drawRect(this->boundingRect());
}
void MyRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
QStyleOptionSizeGrip opt;
opt.corner = Qt::BottomLeftCorner;
opt.rect = boundingRect().toRect();
opt.direction = QApplication::layoutDirection();
opt.palette = QApplication::palette();
opt.fontMetrics = QApplication::fontMetrics();
opt.state = option->state;
pen.setStyle(Qt::SolidLine);
pen.setColor(QColor(Qt::black));
pen.setWidth(1);
if(option->state & QStyle::State_Selected)
{
pen.setStyle(Qt::DashLine);
pen.setColor(QColor(Qt::green));
}
painter->setPen(pen);
QApplication::style()->drawControl(QStyle::CE_SizeGrip, &opt, painter);
painter->drawRect(this->boundingRect());
}
To copy to clipboard, switch view to plain text mode
As you see I'm taking the settings from QApplication. The only problem is with the bounding rectangle. MyRectangles are created with another QGraphicsPixmapItem as a parent (rectangles on an image). The size grip tends to begin inside every rectangle and finish at the top of the parent image... There must be something wrong with the coordinates...
If you have any other suggestions, please reply.
Any help appreciated.
Regards,
Bill
Bookmarks