Changing the border of a QRubberBand
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.
Code:
...
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:
Code:
{
QVector<qreal> dashes;
qreal space = 2;
dashes << 1 << space << 3 << space << 9 << space
<< 2 << space << 2 << space;
pen.setDashPattern(dashes);
pen.setDashOffset(m_offset);
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!
Re: Changing the border of a QRubberBand
Seems like all you need to do is to change "m_offset" in the timeout slot by incrementing it with each timeout (mod( pattern length) so it cycles from 0 to pattern length). Otherwise it looks to me like you have interpreted the dash pattern and offset methods correctly.