Hello again!
As I'm advancing with my little widget, i just got another problem, which is also related with widget painting, so i decided to append my new problem right here in order to not flood the forum. 
I have subclassed my ProgressPie widget to create a timer-controlled progress pie. You give it a range and it counts down or up its limit values. I did this by implementing QObject::startTimer() and the timerEvent() method.
I simply wanted to use my setValue() method from the parent widget which already includes a request to redraw itself after a value change:
repaint(this->rect());
repaint(this->rect());
To copy to clipboard, switch view to plain text mode
But when I call the function from the timerEvent() subclassed widged, nothing happens - unless i resize the window, which will trigger the resizeEvent (which is also implemented in the parent's code and which contains just the same line of code).
When i put the line directly into my timerEvent() method of the subclass, the widget will repaint itself properly every time the timerEvent occurs.
So - why's that?
This is the whole code of both functions:
The setValue() method of the parent class:
void QtProgressPie::setValue(const int &val)
{
// Sets the given value which is checked against its bounds
if (val != _value)
{
_value = qBound(_minimum, val, _maximum);
repaint(this->rect());
}
}
void QtProgressPie::setValue(const int &val)
{
// Sets the given value which is checked against its bounds
if (val != _value)
{
_value = qBound(_minimum, val, _maximum);
repaint(this->rect());
}
}
To copy to clipboard, switch view to plain text mode
The timerEvent() of the subclass:
{
// Modifies the current value of the timed ProgressPie.
// By calling setValue of QtProgressPie, the widget will also be approprietely redrawn. // <--- No, it will not! :-(
// Also, if the minimum or maximum value is arrived, the timerEvent will kill the timer
// and emit the finished()-signal.
if (_countBackwards) // First case: counting towards _minimum
{
this->setValue(--_value); // dec and set value
if (_value == _minimum) // check if value is now equal to the minimum
{ // if yes, kill timer and emit signal
_timerIsRunning = false;
killTimer(e->timerId());
emit finished();
}
}
else // Second case: counting towards _maximum
{
this->setValue(++_value); // inc and set value
if (_value == _maximum) // check if value is now equal to the maximum
{ // if yes, kill timer and emit signal
_timerIsRunning = false;
killTimer(e->timerId());
emit finished();
}
}
repaint(this->rect()); // <--- this seems to be needed, but why?
}
void QtTimedProgressPie::timerEvent(QTimerEvent *e)
{
// Modifies the current value of the timed ProgressPie.
// By calling setValue of QtProgressPie, the widget will also be approprietely redrawn. // <--- No, it will not! :-(
// Also, if the minimum or maximum value is arrived, the timerEvent will kill the timer
// and emit the finished()-signal.
if (_countBackwards) // First case: counting towards _minimum
{
this->setValue(--_value); // dec and set value
if (_value == _minimum) // check if value is now equal to the minimum
{ // if yes, kill timer and emit signal
_timerIsRunning = false;
killTimer(e->timerId());
emit finished();
}
}
else // Second case: counting towards _maximum
{
this->setValue(++_value); // inc and set value
if (_value == _maximum) // check if value is now equal to the maximum
{ // if yes, kill timer and emit signal
_timerIsRunning = false;
killTimer(e->timerId());
emit finished();
}
}
repaint(this->rect()); // <--- this seems to be needed, but why?
}
To copy to clipboard, switch view to plain text mode
EDIT: typo
Bookmarks