Results 1 to 2 of 2

Thread: QPaintEvent on button click?

  1. #1
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question QPaintEvent on button click?

    Hi All,

    I m using Qt 4.1.5 on my Mac.
    I have a paintEvent which is called itself when I create the object of the class having paintEvent().

    Now I want to call the paintEvent on a Button click which is in another class because I m filling the color in the rect on paintevnt and I want to see it column by column.

    But if it is called in the constructor then the whole rect are fill when screen comes up so I want this to be done on button click.

    If any body knows then plz help me.

    thanks.

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPaintEvent on button click?

    You can subclass a QLabel and append the clik event how you like.


    Qt Code:
    1. void FullEdit::PaintDirtyStatus( bool e )
    2. {
    3. QString textd = "nulltext overwrite";
    4. QPixmap pix(140,22); ///// take from label
    5. if (e) {
    6. pix.fill(QColor("crimson")); /* red */
    7. textd = tr("Upload Pending.");
    8. } else {
    9. pix.fill(QColor("lime")); /* green */
    10. textd = tr("Not Upload.");
    11. }
    12. QPainter painter(&pix);
    13.  
    14. QColor textColor = QColor(255,255,255);
    15. QPen pen;
    16. pen.setStyle( Qt::SolidLine );
    17. pen.setColor(textColor);
    18. QFont f( "arial", 8, QFont::Bold );
    19. painter.setFont( f );
    20. painter.setPen( pen);
    21. QFontMetrics fm = painter.fontMetrics();
    22. int largo = fm.width(textd);
    23. painter.drawText(QPointF((pix.width() / 2) - (largo / 2),15),textd);
    24. dirtystartus->setPixmap(pix); /* label */
    25.  
    26. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QGraphicsScene Click / Double Click
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 04:32
  2. Mouse Over event on button
    By vishal.chauhan in forum Qt Programming
    Replies: 9
    Last Post: 10th January 2007, 05:03
  3. Push button double click
    By curtisw in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2006, 16:40
  4. Replies: 5
    Last Post: 12th January 2006, 15:40

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.