Results 1 to 3 of 3

Thread: no frame on Qlabel derived class

  1. #1
    Join Date
    Sep 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question no frame on Qlabel derived class

    Hi all, I am trying to paint with QLabel derived widget and still get widgets frame to be visible. When there is a frame without a drawing function, the frame is shown correctly. The problem is that when I reimplement paintEvent method, the frame is not shown anymore.


    Qt Code:
    1. class GameArea: public QLabel {
    2. public:
    3. GameArea(QWidget *parent = 0);
    4. ~GameArea();
    5.  
    6. protected:
    7. void paintEvent(QPaintEvent *event);
    8. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. label = new GameArea(Exercise2Class);
    2. label->setFrameShape(QFrame::StyledPanel);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void GameArea::paintEvent(QPaintEvent * /* event */)
    2. {
    3. QPainter painter(this);
    4. QPen pen;
    5. QBrush brush;
    6. pen.setColor(Qt::red);
    7. brush.setStyle(Qt::SolidPattern);
    8. brush.setColor(Qt::red);
    9. painter.setPen(pen);
    10. painter.setBrush(brush);
    11. painter.drawEllipse(rect().center(), 20, 20);
    12. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: no frame on Qlabel derived class

    Hi,

    To get something painted what is painted in the base class implementation of paintEvent(), you must call it:
    Qt Code:
    1. void MyDerivedLabel::paintEvent(QPaintEvent* event)
    2. {
    3. QLabel::paintEvent(event); // <---
    4. QPainter painter(this);
    5. ...
    6. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Sep 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: no frame on Qlabel derived class

    Thanks for fast reply. The problem solved...

Similar Threads

  1. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  2. Replies: 2
    Last Post: 20th September 2007, 12:27
  3. Frame in QLabel
    By skrzypu in forum Qt Programming
    Replies: 6
    Last Post: 29th August 2007, 15:23
  4. rtti() of derived class
    By quickNitin in forum Newbie
    Replies: 4
    Last Post: 8th October 2006, 14:20
  5. Signal/slot looking in base class, not derived class
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 07:36

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.