Hello everyone ,,
I'm using qt3 under linux (Debian). I have a large project , but I have a problem in the interface ,, in my project I need a frame for writing on it ,, and and a button for erasing all what was written , and another button that acts as an eraser and of course a button for re-writing on the frame.
The problem was once I write on the frame and erase it ( using QWidget::erase())
and another window come over my window ,, all what was erased before is draw on the frame
This is the constructor of my class
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
|
TextFrame::TextFrame(QWidget *parent) : QFrame(parent)
{
QPixmap a ( QPixmap("Text.png") ) ;
_buffer = a ; // _buffer is private variable of tyep QPixmap
CounterOfPoint = 0 ;
_currentSize=0;
}
|
paintEvent Function
|
Source code
|
1
2
3
4
5
|
void TextFrame :: paintEvent(QPaintEvent*)
{
bitBlt(this , 0 , 0 , &_buffer) ;
}
|
mousePressEvent and mouseMoveEvent approximately the same
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
void TextFrame::mousePressEvent( QMouseEvent * e )
{
// I want to write on frame :
if ( erase == false )
{
_last = e->pos();
// Add point to array of points
Points [CounterOfPoint].x = _last.x() ;
Points [CounterOfPoint].y = _last.y() ;
CounterOfPoint++;
pen.setWidth ( _currentSize) ;
pen.setColor (_currentColor);
windowpainter.begin (this) ;
bufferpainter.begin(& _buffer) ;
windowpainter.setPen (pen);
bufferpainter.setPen (pen);
windowpainter.drawPoint(_last);
windowpainter.end() ;
bufferpainter.end () ;
}
// erase from frame :
else
CheckEraseSize(e);
} //end if
|
|
Source code
|
1
2
3
4
5
6
7
8
9
10
|
and the is the resizeEvent function ,,
void TextFrame :: resizeEvent ( QResizeEvent * event)
{
QPixmap save ( _buffer ) ;
_buffer.resize ( event -> size () ) ;
bitBlt ( &_buffer , 0, 0 , &save ) ;
}
|
EraseCheckSize(e) is jsut a function that checks the size choosed by the user and then use:
QWidget::erase(Region);
for erasing all the frame I could use this code and the prblem disappears , but I don't know how to do if I would only earase some of my drawing not every thing:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
void TextFrame :: EraseAll()
{
CounterOfPoint = 0 ;
_buffer = *(QWidget::erasePixmap ());
QWidget::setErasePixmap (_buffer) ;
}
|
Any help is greatly appreciated..