Friday, July 4th 2008, 11:55pm UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

R.M

Beginner

1

Wednesday, April 16th 2008, 8:50pm

Problem in QPainter

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..

This post has been edited 1 times, last edit by "R.M" (Apr 16th 2008, 9:10pm)

  • Go to the top of the page

R.M

Beginner

2

Friday, April 18th 2008, 12:59pm

up ;(
  • Go to the top of the page

R.M

Beginner

3

Monday, April 28th 2008, 6:18pm

up ..

Am I write my problem in a wrong place ?

This post has been edited 1 times, last edit by "R.M" (May 4th 2008, 6:30pm)

  • Go to the top of the page

Rate this thread