[Qt-interest] Ruler widget not repainting
Anton Chernov
mechernov at gmail.com
Tue Mar 22 09:07:23 CET 2011
> PS: mouseTracking is enabled for all widgets.
Problem:
When this is called it works
void mouseMoveEvent( QMouseEvent* event ) { setCursorPos( event->pos() );
... }
if this it doesn't!
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() ); }
...
}
Arrrrrrgh!
2011/3/21 william.crocker at analog.com <william.crocker at analog.com>
>
>
> Anton Chernov wrote:
> > 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.
> >
>
> Is mouse tracking turned on for the measure widget.
>
> Are you ordering update events for the ruler
> widget whenever the mouse moves over the measure widget.
>
> > 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
> >
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110322/88ce1ab3/attachment.html
More information about the Qt-interest-old
mailing list