Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, March 2002
Prob regarding rubberbanding


Message 1 in thread

Hi Everyone,
Can u just tell me in detail plz as how can i Draw a self-erasing line or a
rubber-band line from a base-point to the current mouse point . This is the
famous and standard XOR'ing problem . The XOR mode is set in the Win32 API
by calling SetROP2.
But I am unable to do it. 
I want to draw a line or a reactangle and  then 'undraw' it. Using the
raster op.
Can U tell me  with the small piece of code.
Regards
Abhay Singh


Message 2 in thread

HAllo Abhay,

here is some sample code.

Just put it as you want it

class xgmceditor
{
...
        QPoint RubberStart,RubberEnd;
        Boolean RubberOn;
...
};

 
void xgmceditor::drawRubber(QPainter *p)
{
  p->drawRect(
              RubberStart.x(),
              RubberStart.y(),
              RubberEnd.x()-RubberStart.x(),
              RubberEnd.y()-RubberStart.y()
             );
}

void xgmceditor::contentsMouseReleaseEvent(QMouseEvent *e)
{
 QPainter p(viewport());
 p.setPen(QColor(255,255,255));
 p.setRasterOp(NotROP);
 if(RubberOn) 
 {
  drawRubber(&p);
  RubberOn=FALSE;
 }
 else
 {
  RubberEnd=RubberStart;
 }
}

void xgmceditor::contentsMouseMoveEvent(QMouseEvent *e)
{
  QPainter p(viewport());
  p.setPen(QColor(255,255,255));
  p.setRasterOp(NotROP);
  if(RubberOn) drawRubber(&p);
  RubberEnd=e->pos();
  drawRubber(&p);
  RubberOn=TRUE;
}

void xgmceditor::contentsMousePressEvent(QMouseEvent *e)
{
 RubberStart=e->pos();
 RubberOn=FALSE;
}


This code worked in my application,
but  I did not test it yet as i just copied out as an example.
They shall just give an idea

rds guenther