Hi,
I'm still trying to draw the resize grip on my custom rectangles, without any luck. Please find attached the header file and source code of my class with an image of the effects of the implementation... Maybe you will spot an error.
I will appreciate any help.
Regards,
Bill
The MyRectangle.h file:
#ifndef __MYRECTANGLE_H__
#define __MYRECTANGLE_H__
#include <QGraphicsRectItem>
{
public:
private:
};
#endif
#ifndef __MYRECTANGLE_H__
#define __MYRECTANGLE_H__
#include <QGraphicsRectItem>
class QPen;
class QStyleOptionGraphicsItem;
class QStyleOptionSizeGrip;
class QPainter;
class MyRectangle : public QGraphicsRectItem
{
public:
MyRectangle(const QRectF &rect, QGraphicsItem *parent = 0);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private:
QPen pen;
};
#endif
To copy to clipboard, switch view to plain text mode
The MyRectangle.cpp file:
#include <QPen>
#include <QStyleOptionGraphicsItem>
#include <QStyleOptionSizeGrip>
#include <QPainter>
#include "myrectangle.h"
{
setFlags(ItemIsMovable|ItemIsSelectable);
}
{
opt.corner = Qt::BottomRightCorner;
opt.rect = boundingRect().toRect();
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());
widget
->style
()->drawControl
(QStyle::CE_SizeGrip,
&opt, painter
);
}
#include <QPen>
#include <QStyleOptionGraphicsItem>
#include <QStyleOptionSizeGrip>
#include <QPainter>
#include "myrectangle.h"
MyRectangle::MyRectangle(const QRectF &rect, QGraphicsItem *parent)
: QGraphicsRectItem(rect,parent)
{
setFlags(ItemIsMovable|ItemIsSelectable);
}
void MyRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionSizeGrip opt;
opt.corner = Qt::BottomRightCorner;
opt.rect = boundingRect().toRect();
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());
widget->style()->drawControl(QStyle::CE_SizeGrip, &opt, painter);
}
To copy to clipboard, switch view to plain text mode
Bookmarks