[Qt-interest] Ruler widget not repainting
Malyushytsky, Alex
alex at wai.com
Mon Mar 21 22:35:24 CET 2011
Check which painter you are using.
I would expect painter pointer paintEvent receive as a aparameter to be passed to drawMouseGuid. Like below:
void paintEvent( QPaintEvent* painter)
{
...
drawMouseGuid( &painter );
}
You seems create painter inside paint Event instead.
Alex
-----Original Message-----
From: qt-interest-bounces+alex=wai.com at qt.nokia.com [mailto:qt-interest-bounces+alex=wai.com at qt.nokia.com] On Behalf Of Anton Chernov
Sent: Monday, March 21, 2011 1:54 PM
To: qt-interest at qt.nokia.com
Subject: [Qt-interest] Ruler widget not repainting
Hi!
Very nervous bug, try already hard for very long time - i am making a ruler widget with showing current cursor position feature and a offseted origin, just like the standard way. The problem is that the current mouse position guids are drawn only when the mouse is over the ruler widget and not when the button is over the widget that i want to "measure" with my ruler.
At first this is my Ruler:
class Ruler : public QWidget {
Q_OBJECT
...
public:
void setCursorPos( const QPoint& cursorPos )
{
if( mCursorPos == cursorPos ) { return; }
mCursorPos = cursorPos;
update();
}
bool eventFilter( QObject* obj, QEvent* event )
{
if( event->type() == QEvent::MouseMove )
{
QMouseEvent* mevent = static_cast( event );
QWidget* widget = qobject_cast( obj );
if( widget ) { setCursorPos( mevent->pos() ); }
/* handle mouse events further */
return false;
}
return QWidget::eventFilter( obj, event );
}
protected:
void mouseMoveEvent( QMouseEvent* event )
{
setCursorPos( event->pos() );
if( !( event->buttons() | Qt::RightButton ) ) { return; }
QDrag* drag = new QDrag( this );
QMimeData* mimeData = new QMimeData;
drag->setMimeData( mimeData );
drag->start( Qt::MoveAction );
}
void paintEvent( QPaintEvent* )
{
...
/* mouse guids */ drawMouseGuid( &painter );
}
void drawMouseGuid( QPainter* painter )
{
QPoint start, end;
switch( mOrientation )
{
case Horizontal: { start.rx() = mCursorPos.x(); start.ry() = 0;
end.rx() = mCursorPos.x(); end.ry() = rect().height(); } break;
case Vertical: { start.rx() = 0; start.ry() = mCursorPos.y();
end.rx() = rect().width(); end.ry() = mCursorPos.y(); } break;
}
painter->save();
QPen pen;
pen.setStyle( Qt::DotLine ); pen.setColor( Qt::black ); pen.setWidth( 1 ); painter->setPen( pen ); painter->setOpacity( 0.4 );
painter->drawLine( start, end );
painter->restore();
}
I have tried 2 ways:
1. in the widget that holds my ruler and my measurable area i implemented the mouseMoveEvent void Preview::mouseMoveEvent( QMouseEvent* event ) {
ui->hRuler->setCursorPos( ui->hRuler->mapFromGlobal( event->globalPos() ) );
QWidget::mouseMoveEvent( event );
}
2. installed on the widget that i want to measure a event filter
ui->previewArea->installEventFilter( ui->hRuler );
Neither off them worked. The positions of the cursor seem to be valid and updated, but the ruler widget itself is repainted only when the mouse is over it or by reactivating the application (alt+tab,
alt+tab). Please help! :)
PS: mouseTracking is enabled for all widgets.
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.
“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”
“Please consider our environment before printing this email.”
More information about the Qt-interest-old
mailing list