Results 1 to 2 of 2

Thread: Qt3To4 port: replacement of QLabel::drawContents method

  1. #1
    Join Date
    Oct 2008
    Location
    Budapest, Hungary
    Posts
    11
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Qt3To4 port: replacement of QLabel::drawContents method

    Hello,

    I try to overwrite a bigger project from Qt3 to Qt4 and there is problem with the method of QLabel::drawContents. I know that drawContents was exiled from Qt4, and the proposed replacement is the usage of paintEvent(QPaintEvent*). I'm confused about replacing a draw function with an event. I suppose at first I have to implement the paintEvent in my class, then I have to call it with (QWidget:: ) update or repaint methods.

    In my exact case there is a new class named ButtonPreview inherited from QLabel. (It is defined as virtual protected in the header file.) Its implementation looks like this in Qt3:

    Qt Code:
    1. void ButtonPreview::drawContents(QPainter *painter)
    2. {
    3. QLabel::drawContents(painter);
    4.  
    5. // ... additional drawing
    6. }
    To copy to clipboard, switch view to plain text mode 

    I suppose QLabel :: drawContents does nothing but I do not want to remove that line, it would be too simple
    I wish to invoke QLabel :: paintEvent. Do I alter drawContents(painter) to "update" or "repaint"? I'm afraid I have to use "repaint" here, paintEvent must be executed immediately and synchronously before the execution of "additional drawing" part.
    The ugliest case is if I have to create ButtonPreview :: paintEvent too with the content of ButtonPreview :: drawContents.

    Brazso

  2. The following user says thank you to brazso for this useful post:


  3. #2
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt3To4 port: replacement of QLabel::drawContents method

    Just call the base class method in your case QLabel:aintEvent( event ); and then below the call initialize new painter and draw whatever you want to draw. If you want to keep your drawContents method do it like this:
    Qt Code:
    1. void ButtonPreview::paintEvent( QPaintEvent* event )
    2. {
    3. QLabel::paintEvent( event );
    4.  
    5. QPainter painter( this );
    6.  
    7. drawContents( &painter ); // ... additional drawing
    8. }
    To copy to clipboard, switch view to plain text mode 

    When you want to get the paintEvent called just call update() or repaint()

    If I missed your point, sorry.

  4. The following user says thank you to The Storm for this useful post:


Similar Threads

  1. QTextDocument: print or drawContents?
    By giusepped in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2010, 08:20
  2. Replies: 1
    Last Post: 29th September 2009, 19:44
  3. qt3to4
    By rishiraj in forum Newbie
    Replies: 1
    Last Post: 19th December 2008, 10:55
  4. Reimplement QSplashScreen::drawContents
    By ucomesdag in forum Qt Programming
    Replies: 12
    Last Post: 24th November 2006, 09:39
  5. drawContents in QScrollArea (Qt4)
    By SkripT in forum Qt Programming
    Replies: 15
    Last Post: 14th January 2006, 10:54

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.