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;
}
{
down = TRUE;
count = 0;
}
{
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();
}
#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();
}
To copy to clipboard, switch view to plain text mode
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 ,, is there any way to draw shapes using in the load time ?
Bookmarks