PDA

View Full Version : use Qpainter to draw lines + problem in my painter



ReSu
3rd March 2008, 18:13
Hello everyone ,,

first of all I'm using Qt3 , and I work on Debian,,

I try to modify drawlines.cpp code in example package of QT3 because I want my own painter program ,,

what I want in my program is to have a white box and some other buttons ,, but I have a problem in my try :( , I want the drawn lines just appears in this white box but now the user can draw anywhere in the frame ,, I try to solve this problem by passing the name of the label (the white box) to the constructor of QPainter , But I have something strange :) mybe it is not strange for advanced programmer ,, the problem was the user could draw correctly but she has to put the mouse not on the white space BUT in a place above it with about 7 cm !
here is the modified code





#include <qpainter.h>
#include <stdlib.h>



const int MAXPOINTS = 4000; // maximum number of points


void mousewriting::init()
{

count = 0;
down = FALSE;
points = new QPoint[MAXPOINTS];

}


void mousewriting::destroy()
{

delete[] points;

}




void mousewriting::mousePressEvent( QMouseEvent * )
{

down = TRUE;
count = 0;
}


void mousewriting::mouseMoveEvent( QMouseEvent *e )
{

if ( down && count < MAXPOINTS ) {
QPainter paint(this); \\ I replace this by textLabel1 (the white box)
// paint.setWindow ( 170, 140, 400, 500 );
points[count++] = e->pos(); // add point
paint.drawPoint( e->pos() ); // plot point

for ( int i=0; i<count-1; i++ ) {
for ( int j=i+1; j<i+2; j++ ) {

paint.setPen( blue);
paint.drawLine( points[i], points[j] ); // draw line
paint.flush() ;
}//end inner for
}//end outer for


}//end if

}//end funcion


void mousewriting::cleardraw()
{
down= false;
update();
}




could anyone help me :( ,, or give me an idea to have a frame and iside it a white space for drawing in it ??

another question , I try to draw using functions of QPainter class in the load of the program , I put it the code in the init() but it does not draw:confused: ,, is there any way to draw shapes using in the load time ?

ReSu
4th March 2008, 00:17
I could draw lines now in paintEvent() and the lines appeared at the run of the program ,,

But the main problem still exists, the drawn curves are not exactly drawn with the head of the mouse , they change accouding to the white box position :confused:, I try to search fo a solution but I'm a very beginner in qt3 :crying:

any helps are greaaaaately appreciated :o

ReSu
4th March 2008, 22:03
No help :(:(

all what i want is to draw inside a frame or label , I have read some links but all my try fails :(:(

impeteperry
5th March 2008, 16:38
I don't understand posting your problem in an e-mail I received directly. I suggest you post your problem in the Qt Center Forum directly.

I have switched from Qt 3 to Qt 4. They have made drastic changes in the "painter" . You may want to look at your problem from that prospective.

Sorry, but I will not open any more of your e-mails sent directly to me if they contain any Qt content.

Good luck

wysota
5th March 2008, 16:44
Could you provide a minimal compilable example reproducing the problem?