Results 1 to 5 of 5

Thread: use Qpainter to draw lines + problem in my painter

  1. #1
    Join Date
    Feb 2008
    Posts
    4
    Platforms
    Unix/X11

    Default use Qpainter to draw lines + problem in my painter

    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

    Qt Code:
    1. #include <qpainter.h>
    2. #include <stdlib.h>
    3.  
    4.  
    5.  
    6. const int MAXPOINTS = 4000; // maximum number of points
    7.  
    8.  
    9. void mousewriting::init()
    10. {
    11.  
    12. count = 0;
    13. down = FALSE;
    14. points = new QPoint[MAXPOINTS];
    15.  
    16. }
    17.  
    18.  
    19. void mousewriting::destroy()
    20. {
    21.  
    22. delete[] points;
    23.  
    24. }
    25.  
    26.  
    27.  
    28.  
    29. void mousewriting::mousePressEvent( QMouseEvent * )
    30. {
    31.  
    32. down = TRUE;
    33. count = 0;
    34. }
    35.  
    36.  
    37. void mousewriting::mouseMoveEvent( QMouseEvent *e )
    38. {
    39.  
    40. if ( down && count < MAXPOINTS ) {
    41. QPainter paint(this); \\ I replace this by textLabel1 (the white box)
    42. // paint.setWindow ( 170, 140, 400, 500 );
    43. points[count++] = e->pos(); // add point
    44. paint.drawPoint( e->pos() ); // plot point
    45.  
    46. for ( int i=0; i<count-1; i++ ) {
    47. for ( int j=i+1; j<i+2; j++ ) {
    48.  
    49. paint.setPen( blue);
    50. paint.drawLine( points[i], points[j] ); // draw line
    51. paint.flush() ;
    52. }//end inner for
    53. }//end outer for
    54.  
    55.  
    56. }//end if
    57.  
    58. }//end funcion
    59.  
    60.  
    61. void mousewriting::cleardraw()
    62. {
    63. down= false;
    64. update();
    65. }
    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 ?

  2. #2
    Join Date
    Feb 2008
    Posts
    4
    Platforms
    Unix/X11

    Question Re: use Qpainter to draw lines + problem in my painter

    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 , I try to search fo a solution but I'm a very beginner in qt3

    any helps are greaaaaately appreciated
    Attached Files Attached Files

  3. #3
    Join Date
    Feb 2008
    Posts
    4
    Platforms
    Unix/X11

    Default Re: use Qpainter to draw lines + problem in my painter

    No help

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

  4. #4
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: use Qpainter to draw lines + problem in my painter

    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

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: use Qpainter to draw lines + problem in my painter

    Could you provide a minimal compilable example reproducing the problem?

Similar Threads

  1. qpainter "drawText() problem
    By impeteperry in forum Qt Programming
    Replies: 10
    Last Post: 25th March 2007, 00:46
  2. How to draw lines with the right width?
    By albanelporto in forum Qt Programming
    Replies: 3
    Last Post: 22nd November 2006, 11:51
  3. How to manage QPainter?
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.