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

    Hi wysota!,
    Can you please help me with this???

    Waiting for a reply!!!!!!

  2. #2
    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

    The below solution draws only a single line. How to draw two or more lines???

    Qt Code:
    1. void setRasterOpTest::mousePressEvent( QMouseEvent *e ){
    2. if (e->button() == Qt::LeftButton) {
    3. m_firstpt = e->pos();
    4. m_lastpt = e->pos();
    5. }
    6. }
    7.  
    8. void setRasterOpTest::mouseMoveEvent( QMouseEvent *e ){
    9. if ((e->buttons() & Qt::LeftButton) ){
    10. m_lastpt = e->pos();
    11. update();
    12. }
    13. }
    14.  
    15. void setRasterOpTest::mouseReleaseEvent(QMouseEvent *e){
    16. if (e->button() == Qt::LeftButton ) {
    17. m_lastpt = e->pos();
    18. update();
    19. }
    20. }
    21.  
    22. void setRasterOpTest::paintEvent(QPaintEvent *e){
    23. QPainter painter(this);
    24. painter.setPen( Qt::black );
    25. painter.drawLine(m_firstpt, m_lastpt);
    26. }
    To copy to clipboard, switch view to plain text mode 

  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

    One more solution, Now this draws so many lines.. I'm trying and let you know if I get it...
    Here is the program...

    Qt Code:
    1. void setRasterOpTest::mousePressEvent( QMouseEvent *e ){
    2. if (e->button() == Qt::LeftButton) {
    3. m_firstpt = e->pos();
    4. m_lastpt = e->pos();
    5. }
    6. }
    7.  
    8. void setRasterOpTest::mouseMoveEvent( QMouseEvent *e ){
    9. if ((e->buttons() & Qt::LeftButton) ){
    10. m_lastpt = e->pos();
    11. update();
    12. }
    13. }
    14.  
    15. void setRasterOpTest::mouseReleaseEvent(QMouseEvent *e){
    16. if (e->button() == Qt::LeftButton ) {
    17. m_lastpt = e->pos();
    18. update();
    19. }
    20. }
    21.  
    22. void setRasterOpTest::paintEvent(QPaintEvent *e){
    23. QPainter painter(this);
    24. painter.setPen( Qt::black );
    25. m_vectorLine << QLine( m_firstpt, m_lastpt );
    26. painter.drawLines( m_vectorLine );
    27. }
    To copy to clipboard, switch view to plain text mode 

    If you get it before please let me know...
    Thanks

  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

    Sorry, I've been unavailable.

    Maybe you should change your concept a little and make it so that you click and drag with left mouse button and when you want to finish a line segment, you click with right mouse button.

    It would look more or less like so:
    Qt Code:
    1. void setRasterOpTest::mousePressEvent *e){
    2. if(e->button()==Qt::LeftButton){
    3. m_list.clear();
    4. m_list << e->pos();
    5. m_lastpt = e->pos();
    6. } else if(e->button()==Qt::RightButton){
    7. m_list << e->pos();
    8. m_lastpt = e->pos();
    9. }
    10. }
    11. void setRasterOpTest::mouseMoveEvent( QMouseEvent *e )
    12. {
    13. m_lastpt = e->pos();
    14. update();
    15. }
    16. void setRasterOpTest::mouseReleaseEvent(QMouseEvent *e){
    17. if(e->button()==Qt::LeftButton()){
    18. if(m_list.size()==1 && (e->pos()-m_list[0]).manhattanLength()<5){
    19. m_list.clear();
    20. update();
    21. return;
    22. }
    23. m_list << e->pos();
    24. m_lastpt = QPoint();
    25. update();
    26. }
    27. }
    28. void setRasterOpTest::paintEvent(QPaintEvent *e){
    29. //... (do regular stuff here)
    30. if(!m_list.isEmpty()){
    31. painter.save();
    32. painter.setPen(Qt::black);
    33. painter.drawLines(m_list);
    34. painter.setPen(Qt::red);
    35. painter.drawLine(m_list[m_list.size()-1], m_lastpt);
    36. painter.restore();
    37. }
    38. }
    To copy to clipboard, switch view to plain text mode 


    EDIT: A complete working example is attached.
    Attached Files Attached Files
    Last edited by wysota; 30th March 2007 at 11:16.

  5. #5
    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

    Hi wysota,
    My application is something like QPainter in MS where you can draw different kind of molecules (in chemistry term). The product is now to be ported to qt4. If I change the functionality (which is not a good idea) of drawing operations, I'll have tough time with my client.

    The above sample program is the first step (where I should be able to draw two or more straight lines) to move forward.

    I think you can understand my problem so please help me to achieve the same functionality as setRasterOp in qt3 performs.

    Waiting eagerly for a reply....

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.