Something like this
void RubberBand::onPasteBtn(){
qApp->installEventFilter( this );
qApp->enter_loop();
}
{
//other stuffs
}
{
//other stuffs
}
{
//other stuffs
}
if( (e
->type
() == QEvent::Paint) ||
(e
->type
() == QEvent::Resize) ||
(e
->type
() == QEvent::FocusIn) ||
(e
->type
() == QEvent::FocusOut) ) {
return FALSE;
}
if ( e
->type
() == QEvent::KeyPress && ((QKeyEvent *)e
)->key
() == Qt
::Key_Escape ){ // remove this event filter and exit the current event loop
qApp->removeEventFilter( this );
qApp->exit_loop();
delete m_Rubberband;
m_Rubberband = 0;
return TRUE;
}
if( e
->type
() == QEvent::MouseMove ){
m_pasteRect.
setBottom( ((QMouseEvent *)e
)->pos
().
x() + 50 );
m_pasteRect.
setRight( ((QMouseEvent *)e
)->pos
().
y() + 50 );
if( !m_Rubberband )
m_Rubberband->setGeometry( m_pasteRect );
m_Rubberband->show();
return TRUE;
}
else if( e
->type
() == QEvent::MouseButtonRelease ){ // remove this event filter and exit the current event loop
qApp->removeEventFilter( this );
qApp->exit_loop();
delete m_Rubberband;
m_Rubberband = 0;
return TRUE; // eat event
}
return TRUE; // block standard event processing
}
void RubberBand::onPasteBtn(){
qApp->installEventFilter( this );
qApp->enter_loop();
}
void RubberBand::mousePressEvent(QMouseEvent *event)
{
//other stuffs
}
void RubberBand::mouseMoveEvent(QMouseEvent *event)
{
//other stuffs
}
void RubberBand::mouseReleaseEvent(QMouseEvent *event)
{
//other stuffs
}
bool RubberBand::eventFilter( QObject *obj, QEvent *e ){
if( (e->type() == QEvent::Paint) || (e->type() == QEvent::Resize) ||
(e->type() == QEvent::FocusIn) || (e->type() == QEvent::FocusOut) )
{
return FALSE;
}
if ( e->type() == QEvent::KeyPress && ((QKeyEvent *)e)->key() == Qt::Key_Escape ){
// remove this event filter and exit the current event loop
qApp->removeEventFilter( this );
qApp->exit_loop();
delete m_Rubberband;
m_Rubberband = 0;
return TRUE;
}
if( e->type() == QEvent::MouseMove ){
m_pasteRect.setTop( ((QMouseEvent *)e)->pos().x() );
m_pasteRect.setLeft( ((QMouseEvent *)e)->pos().y() );
m_pasteRect.setBottom( ((QMouseEvent *)e)->pos().x() + 50 );
m_pasteRect.setRight( ((QMouseEvent *)e)->pos().y() + 50 );
if( !m_Rubberband )
m_Rubberband = new QRubberBand(QRubberBand::Rectangle, this);
m_Rubberband->setGeometry( m_pasteRect );
m_Rubberband->show();
return TRUE;
}
else if( e->type() == QEvent::MouseButtonRelease ){
// remove this event filter and exit the current event loop
qApp->removeEventFilter( this );
qApp->exit_loop();
delete m_Rubberband;
m_Rubberband = 0;
return TRUE; // eat event
}
return TRUE; // block standard event processing
}
To copy to clipboard, switch view to plain text mode
Now in the above code there are both events and eventFilter. So do you still I'm doing something wrong above. Please bear with me. I want to clear my fundas...
Thanks
Bookmarks