Results 1 to 2 of 2

Thread: Paintevent and update

  1. #1
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Paintevent and update

    Hi,

    I have a requirement, wherein i receive data from a socket, to be continuously drawn on the widget.
    The socket is pumping data with the worst case speed of 1ms.

    I have a thread to receive the data, after reception i copy the data into the widget's member to be drawn, then i call the update() function.

    here i have two problems
    1.Update requires some time to finish its job, but by this time there is a possibility of receiving new data.
    here i may miss soem data from socket or painting for that set is incomplete ...

    2.For the sake of optimization, its said that "Calling update() several times normally results in just one paintEvent() call." so in this case what happens to the data which is to be drawn for each update?
    i.e. lets say i received 4 data which would result in calling 4 updates and ideally the widget was supposed to be redrawn 4 times.
    but due to this optimization i may have only the last data read.

    Can anybody suggest what needs to be done for this, i think i need to implement a buffer, but i dont know how to pass this info for PaintEvent.

    Thanks in advance

  2. #2
    Join Date
    Dec 2007
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Paintevent and update

    1. If you have a separate thread receiving data, you just have to make sure that tread checks your socket often enough, right?

    2. If you copy data to the widget, is the old data overwritten or added to existing data? If it is added, you already have all data, so no need to buffer. If it is overwritten, and your data has not been drawn on the widget yet, your data will be lost.

    3. Update combines all drawing into one paint event, so everything will be drawn. If you have an animation type of widget that erases the previous data, than you are right that in your example of 4 data received, and combined in one paint event, you will see only the last data. In that case you can try if using the QWidget::repaint () function solves your problem.

    4. If repaint() is slower then your data stream, and you don't mind seeing a delay between the received data and the widget drawing, you need to implement a buffer class that calls the repaint function as long as there is data that needs to be shown.

    Wim

Similar Threads

  1. QPainter update()
    By csvivek in forum Qt Programming
    Replies: 5
    Last Post: 24th March 2008, 09:42
  2. Calling update() from paintEvent()
    By wonder.mice in forum Qt Programming
    Replies: 8
    Last Post: 11th January 2008, 13:41
  3. Widget does not update
    By Caius Aérobus in forum Qt Programming
    Replies: 2
    Last Post: 2nd January 2008, 22:26
  4. painting a widget outside a paintEvent
    By jayw710 in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2007, 23:18
  5. New thread to handle paintEvent
    By bitChanger in forum Qt Programming
    Replies: 1
    Last Post: 9th March 2006, 21:41

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.