Results 1 to 20 of 23

Thread: setRasterOp Equivalent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setRasterOp Equivalent

    And here is the code that I want....

    Qt Code:
    1. #include "setrasteroptest.h"
    2. #include <QMouseEvent>
    3. #include <QPainter>
    4.  
    5. //Program to draw a straight line using Qt4
    6. //constructor
    7. setRasterOpTest::setRasterOpTest(QWidget *parent, Qt::WFlags flags)
    8. : QFrame(parent, flags)
    9. {
    10. ui.setupUi(this);
    11. QColor color( Qt::white );
    12. QPalette palette;
    13. palette.setColor(backgroundRole(), color);
    14. setPalette(palette);
    15. setMouseTracking(true);
    16. m_bflag = false;
    17. }
    18.  
    19. setRasterOpTest::~setRasterOpTest()
    20. {}
    21.  
    22. void setRasterOpTest::mousePressEvent( QMouseEvent *e ){
    23. if (e->button() == Qt::LeftButton){
    24. m_firstpt = e->pos();
    25. m_lastpt = e->pos();
    26. }
    27. }
    28.  
    29. void setRasterOpTest::mouseMoveEvent( QMouseEvent *e ){
    30. if ((e->buttons() & Qt::LeftButton) ){
    31. m_lastpt = e->pos();
    32. m_bflag = true;
    33. update();
    34. }
    35. }
    36.  
    37. void setRasterOpTest::mouseReleaseEvent(QMouseEvent *e){
    38. if (e->button() == Qt::LeftButton ) {
    39. m_lastpt = e->pos();
    40. m_vectorLine << QLine( m_firstpt, m_lastpt );
    41. update();
    42. }
    43. }
    44.  
    45. void setRasterOpTest::paintEvent(QPaintEvent *e){
    46. QPainter painter(this);
    47. painter.setPen( Qt::black );
    48. painter.drawLines( m_vectorLine );
    49.  
    50. if( m_bflag ){
    51. painter.drawLine( m_firstpt, m_lastpt );
    52. m_bflag = false;
    53. }
    54. }
    To copy to clipboard, switch view to plain text mode 

    Thanks wysota!!!!

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

    Default Re: setRasterOp Equivalent

    What is the m_bflag for? No matter what it is, you use it incorrectly. You surely shouldn't zero the flag in a paint event.

  3. #3
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setRasterOp Equivalent

    Quote Originally Posted by wysota View Post
    What is the m_bflag for? No matter what it is, you use it incorrectly. You surely shouldn't zero the flag in a paint event.
    Hi wysota,
    The m_bflag helps me to see the line on mouseMove. Without this the line is not visible when I move the mouse.

    I have attached the complete solution.

    Let me know if I'm doing anything wrong.

    Thanks
    Attached Files Attached Files

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

    Default Re: setRasterOp Equivalent

    What happens if you drag a line and suddenly some window from another application pops up obscuring a part of your widget? A paint event will come and as your flag will be set to false by the previous paint event, the "dynamic" line will not be redrawn. Instead you should clear the flag in mouseReleaseEvent. And don't use the flag - just clear m_lastPt - it'll return true on QPoint::isNull() call. Then it's only a matter of checking that point in the paint event and drawing the line only if isNull() returns false. Just look at one of my previous examples.

Similar Threads

  1. Replies: 2
    Last Post: 23rd April 2006, 01:02
  2. what's the equivalent with DPtoLP in windows
    By cocalele in forum Qt Programming
    Replies: 6
    Last Post: 1st March 2006, 06:57
  3. make install equivalent in qmake ...
    By momesana in forum Newbie
    Replies: 3
    Last Post: 20th February 2006, 21:46
  4. PostMessage() across process boundaries equivalent
    By TheKedge in forum Qt Programming
    Replies: 9
    Last Post: 27th January 2006, 00:02

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
  •  
Qt is a trademark of The Qt Company.