Results 1 to 2 of 2

Thread: Painting Problem on Mac

  1. #1
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Painting Problem on Mac

    hi Everybody .

    I am using Qt 4.2 , on Mac OS

    Please execute this code on Mac OS.

    After button click setMask called .
    when i want to do repainting ,
    painting in side the widget is moving .


    sample.cpp

    Qt Code:
    1. myWidget::myWidget(QWidget *parent): QWidget(parent)
    2. {
    3. bRgnSet=false;
    4. QPushButton *quit = new QPushButton("Click", this);
    5. quit->setFont(QFont("Times", 18, QFont::Bold));
    6. quit->setGeometry(75,75,30,30);
    7. setGeometry(0, 0, 400, 400);
    8. connect(quit, SIGNAL(clicked()), this, SLOT(ButtonPressed()));
    9.  
    10. m_ptArr1[0] = QPoint(50,50);
    11. m_ptArr1[1] = QPoint(380,120);
    12. m_ptArr1[2] = QPoint(280,350);
    13. m_ptArr1[3] = QPoint(80,180);
    14. m_ptArr1[4] = QPoint(50,50);
    15.  
    16. }
    17.  
    18. void myWidget::paintEvent(QPaintEvent *)
    19. {
    20. QPainter painter(this);
    21. painter.setPen(Qt::blue);
    22.  
    23. painter.drawRect(100,100,200,200);
    24. painter.drawEllipse(150,150,100,100);
    25.  
    26. if(bRgnSet)
    27. {
    28. painter.translate(50,50);
    29. }
    30.  
    31. if(bRgnSet)
    32. {
    33. painter.drawEllipse(300,300,50,50);
    34. painter.drawLine(0,0,400,400);
    35. }
    36.  
    37. }
    38.  
    39. void myWidget::ButtonPressed()
    40. {
    41. //QRegion widgetRgn(54,39,200,200,QRegion::Ellipse);
    42. bRgnSet = true;
    43. QPolygon rlPolygon;
    44. rlPolygon.setPoints(5, m_ptArr1[0].x(), m_ptArr1[0].y(), m_ptArr1[1].x(), m_ptArr1[1].y(),
    45. m_ptArr1[2].x(), m_ptArr1[2].y(), m_ptArr1[3].x(), m_ptArr1[3].y(), m_ptArr1[4].x(), m_ptArr1[4].y(),
    46. m_ptArr1[5].x(), m_ptArr1[5].y());
    47. QRegion rlRegion(rlPolygon);
    48. setMask( rlPolygon );
    49. //setMask( widgetRgn );
    50.  
    51. }
    52.  
    53. int main(int argc, char *argv[])
    54. {
    55. QApplication app(argc, argv);
    56. myWidget widget;
    57.  
    58. widget.show();
    59. return app.exec();
    60. }
    To copy to clipboard, switch view to plain text mode 



    sample.h



    Qt Code:
    1. class myWidget: public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. QPoint m_ptArr1[5];
    6. bool bRgnSet;
    7. myWidget(QWidget *parent = 0);
    8. void paintEvent(QPaintEvent *);
    9.  
    10. public slots:
    11. void ButtonPressed();
    12. };
    To copy to clipboard, switch view to plain text mode 


    Add appropriate header files to sample .cpp & sample.h


    Implement repaint after clicking the button .


    Any body knows the reason pls revert me back .

    Thankyou

    Shyam Boga
    Last edited by jacek; 2nd February 2007 at 11:01. Reason: wrapped too long line

  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: Painting Problem on Mac

    What do you mean that it is moving?

Similar Threads

  1. Painting Problem
    By shyam prasad in forum Qt Programming
    Replies: 3
    Last Post: 5th February 2007, 15:07
  2. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 13:54
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 15:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 22:36
  5. Replies: 16
    Last Post: 7th March 2006, 16: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.