Sergex
31st July 2012, 17:28
Hello,
In my program I draw rectangle rubberbands on a QGraphicsView with the mouse and I now I want to have the border of the rubber band have a marching ant kind of effect.
The first thing I am trying to to is subclassing the QRubberband and re-implementing the paintEvent. And also set the effect using a QTimer.
The QTimer is in my QGV class.
I simply set the timer up there.
...
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(updateBorder()));
m_timer->start(400);
...
void WaveObject::updateBorder()
{
m_rubberBand->update(); //MyRubberBand object
}
Then in my QRubberband subclass I am trying a few things:
void MyRubberBand::paintEvent(QPaintEvent *event)
{
QPen pen;
QVector<qreal> dashes;
qreal space = 2;
dashes << 1 << space << 3 << space << 9 << space
<< 2 << space << 2 << space;
pen.setDashPattern(dashes);
pen.setDashOffset(m_offset);
QStylePainter painter(this);
QStyleOptionRubberBand option;
initStyleOption(&option);
painter.setPen(pen);
painter.drawControl(QStyle::CE_RubberBand, option);
}
This doesn't do anything yet, which si expected because I don't really understand very well how the offset and setting patterns work. Can someone point in the right direction ?? Any help much appreciated.
Thanks!
In my program I draw rectangle rubberbands on a QGraphicsView with the mouse and I now I want to have the border of the rubber band have a marching ant kind of effect.
The first thing I am trying to to is subclassing the QRubberband and re-implementing the paintEvent. And also set the effect using a QTimer.
The QTimer is in my QGV class.
I simply set the timer up there.
...
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(updateBorder()));
m_timer->start(400);
...
void WaveObject::updateBorder()
{
m_rubberBand->update(); //MyRubberBand object
}
Then in my QRubberband subclass I am trying a few things:
void MyRubberBand::paintEvent(QPaintEvent *event)
{
QPen pen;
QVector<qreal> dashes;
qreal space = 2;
dashes << 1 << space << 3 << space << 9 << space
<< 2 << space << 2 << space;
pen.setDashPattern(dashes);
pen.setDashOffset(m_offset);
QStylePainter painter(this);
QStyleOptionRubberBand option;
initStyleOption(&option);
painter.setPen(pen);
painter.drawControl(QStyle::CE_RubberBand, option);
}
This doesn't do anything yet, which si expected because I don't really understand very well how the offset and setting patterns work. Can someone point in the right direction ?? Any help much appreciated.
Thanks!