Results 1 to 5 of 5

Thread: Problem in paintEvent()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Problem in paintEvent()

    Hi Experts
    I have problem in my painEvent() , the function is get called many times but get nothing draw on the widget.I understand why the function is gett called so much time but how to resolve this.

    I am drawing a hexagon

    Qt Code:
    1. void MainWindow::paintEvent(QPaintEvent *event )
    2. {
    3. QPainter painter(this);
    4. painter.setRenderHint(QPainter::Antialiasing);
    5. QPen pen(Qt::black);
    6. pen.setWidth(6);
    7. painter.setPen(pen);
    8.  
    9. static const QPointF points[6] = {
    10. QPointF(300.0, 160.0),//Top Line
    11. QPointF(220.0, 160.0),//
    12. //QPointF(300.0, 180.0),
    13. QPointF(195.0, 210.0),
    14. QPointF(220.0, 260.0),//
    15. QPointF(300.0, 260.0),//Bottom Line
    16. QPointF(325.0, 210.0)
    17. };
    18. painter.drawPolygon(points, 6);
    19. qDebug() << "Cnt=" << cnt;
    20. cnt++;
    21.  
    22. QPainter painter1(this);
    23. QPen pen1(Qt::green);
    24. painter1.setPen(pen1);
    25. QLinearGradient grad1(300, 160, 325, 260);
    26. QBrush brush1(grad1);
    27. grad1.setColorAt(1.0, Qt::white);
    28. painter1.setBrush(brush1);
    29. QFont font("Times", 12);
    30. painter1.setFont(font);
    31. QPoint point1 = QPoint( 240, 225);
    32. painter1.drawText( point1, text_str );
    33. }
    To copy to clipboard, switch view to plain text mode 

    and


    Qt Code:
    1. NewWindow::NewWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::NewWindow)
    4. {
    5. ui->setupUi(this);
    6. QString string = "Gello";
    7. w1 = new MainWindow(string ,this);
    8. w1->show();
    9. }
    To copy to clipboard, switch view to plain text mode 


    Please guide me i am trying to resolve this since 1 day.
    Is i have to call paintEvent() manually but i read at a place there is no need to call it manually.
    Thanks.
    Waiting for your reply.
    Last edited by Lykurg; 10th May 2011 at 06:40.

Similar Threads

  1. paintEvent method problem
    By zgulser in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2010, 12:32
  2. paintEvent problem
    By di_zou in forum Newbie
    Replies: 5
    Last Post: 2nd September 2009, 16:13
  3. Problem with QListWidget and paintEvent()
    By joksi in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2009, 10:50
  4. paintEvent problem
    By anafor2004 in forum Newbie
    Replies: 1
    Last Post: 29th June 2008, 14:18
  5. paintEvent problem
    By MoaLaiSkirulais in forum Qt Programming
    Replies: 5
    Last Post: 12th February 2008, 13:59

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.