Results 1 to 4 of 4

Thread: QT3 to Qt4 port - problem seeing Ellipse etc

  1. #1
    Join Date
    Mar 2008
    Posts
    3
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QT3 to Qt4 port - problem seeing Ellipse etc

    Hello,
    I'm new to the forum and have a problem porting a science program from QT3.*.* on linux to qt4 on windows XP sp2. By the way, I'm an old fortran programmer and know little about Qt.

    I have the program running correctly on Opensuse 10.2/Qt3.3.8.

    For the code that doesn't work correctly on XP the user is supposed to:
    1) Left-mouse select a point,
    2) then hold down the left-mouse and drag an ellipse across an area of interest,
    3) release the mouse and the underlying screen image is altered according to the ellipse area covered.

    However, on the XP version the ellipse does not appear.

    The relevent code is summarised below.


    Qt Code:
    1. void strPlot::mousePressEvent( QMouseEvent *e)
    2. pixmapa = QPixmap::grabWidget(this);
    3.  
    4. if ( e->button() == Qt::LeftButton )
    5. //here I've left out that defines screen coords etc.
    6.  
    7.  
    8.  
    9. void strPlot::mouseMoveEvent( QMouseEvent *e)
    10. {
    11.  
    12. int idx, nr_pryzmy;
    13. QRect rr;
    14. QPoint punkt;
    15. int temp_x1,temp_z1,z_szer=0,z_wys=0;
    16. double xm,zm;
    17.  
    18. QPainter p( this );
    19.  
    20. if(e->state() & Qt::LeftButton)
    21. {
    22. if(click_x1>click_x2)
    23. {
    24. temp_x1 = click_x2;
    25. click_x2 = click_x1;
    26. }
    27.  
    28. if(click_z1>click_z2)
    29. {
    30. temp_z1 = click_z2;
    31. click_z2 = click_z1;
    32. }
    33.  
    34. if(click_x1<xel) click_x1 = xel;
    35. if(click_x2>xer) click_x2 = xer;
    36. if(click_z1<yel) click_z1 = yel;
    37. if(click_z2>yer) click_z2 = yer;
    38.  
    39. z_szer = click_x2 - click_x1;
    40. z_wys = click_z2 - click_z1;
    41.  
    42. rr = QRect(temp_x1,temp_z1,z_szer,z_wys);
    43.  
    44. bitBlt(this,0,0,&pixmapa);
    45.  
    46. //rysuj_prostokaty(&p);
    47. //repaint(rr);
    48. p.setBrush(NoBrush);
    49. p.setPen(QPen(black,2));
    50. p.setPen(DashLine);
    51. if(z_ksztalt==1 || z_ksztalt==-1) p.drawRect(rr);
    52.  
    53. if(z_ksztalt==2)p.drawEllipse(rr); // THIS IS THE BIT THAT FAILS
    54.  
    55. }
    56. }
    57.  
    58. void strPlot::mouseReleaseEvent( QMouseEvent *e)
    59.  
    60. //here I've left out a lot of subsiduary code etc.
    61.  
    62. if(z_ksztalt==2)
    63. {
    64. rr = QRect(click_x1,click_z1,z_szer,z_wys) ;
    65. zmien_stan(QRegion(rr,QRegion::Ellipse));
    66.  
    67. }
    68. }
    69. }
    70. //Tanimbar: the update below causes the selected blocks to change density colour
    71. update();
    72. QPainter p( this );
    73. rysuj_prostokaty(&p);
    74. }
    To copy to clipboard, switch view to plain text mode 

    As I understand the code the following is supposed to happen:
    1) on MousePressevent a pixmap is grabbed,
    2) on MouseMovement the pixmap is passed to bitBlt and overdrawn on top of the, now, underlying widget,
    3) while the Mouse is moving an ellipse should be drawn on the pixmap,
    4) on Mousereleaseevent the pixmap disappears and the underlying widget is updated with new information, a colour change to blocks, formerly delineated by the ellipse.

    However, after extensive trials, much reading of manuals and forums, I still cannot get the ellipse to become visible. Everything else works, including the events/actions required on MousereleaseEvent.

    Can anyone help - hints, tips suggestions?

    Thanks in advance.
    Last edited by wysota; 5th March 2008 at 12:47.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QT3 to Qt4 port - problem seeing Ellipse etc

    In Qt4 you can only paint within paintEvent. But I suggest you do it differently - use QRubberBand class. By default it's rectangular, so you'll have to subclass it.

  3. #3
    Join Date
    Mar 2008
    Posts
    3
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT3 to Qt4 port - problem seeing Ellipse etc

    Wysota,
    Thank you for the information - I now know what to look at.

    Thanks for editing my original message.

    regards, Tanimbar

  4. #4
    Join Date
    Mar 2008
    Posts
    3
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT3 to Qt4 port - problem seeing Ellipse etc

    Thanks for Wysota for the QrubberBand tip/hint. That works very well for the situation described in my first note, i.e., dragging a rectangle over a widget by the user to define an area of interest.

    It occured to me that QrubberBand, using Line and not Rectangle, might also work for the case where the user mousepresses, drags a line to new point, mousereleases and then, mousepresses again to continue defining a polyline around an area of interest.

    But I can't get QRubberBand::Line to work: the program always draws a Rectangle.

    I've tried various style options, for example, QWindowsXPstyle, and all sorts of code variations but can't get Qrubberband to use a line.

    There was a bug related to QRubberband not using Line but that is reported as fixed http://trolltech.org/developer/task-...entry&id=78876.

    The code below is the present example that doesn't draw a line.

    Qt Code:
    1. void strPlot::mousePressEvent( QMouseEvent *e)
    2. {
    3.  
    4. double xm,zm;
    5. int x,y;
    6. QPoint punkt;
    7. // pixmapa = QPixmap::grabWidget(this);
    8. if ( e->button() == Qt::LeftButton )
    9. .
    10. .
    11. .
    12. origin = e->pos();
    13. if (!rubberBand)
    14. rubberBand->setStyle( (QStyle*)new QWindowsXPStyle() );
    15. rubberBand = new QRubberBand(QRubberBand::Line, this);
    16. // works rubberBand->setGeometry(click_x1,click_z1,5,5);
    17. rubberBand->setGeometry(QRect(origin, QSize(1,1)));
    18. rubberBand->show();
    19. .
    20. .
    To copy to clipboard, switch view to plain text mode 

    So, a couple of questions:
    1) Does anyone have a working example of QRubberBand using Line?
    2) Does anyone know if a bug still exists for QRubberBand line?
    3) Does anyone have a suggestion/fix/hint?

    By the way, I'm an old fortran programmer, don't know C++ or Qt (sorry) and using Qt4.3.4 OpenSource on a Windows XP SP2 system.

    Thanks very much.

Similar Threads

  1. problem while compiling qextserial port
    By jjbabu in forum Qt Programming
    Replies: 1
    Last Post: 15th September 2007, 13:01
  2. Replies: 6
    Last Post: 18th April 2007, 15:04
  3. Replies: 16
    Last Post: 7th March 2006, 15:57

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.