Results 1 to 5 of 5

Thread: Qt 5.5.1 + QwtPlotDirectPainter = a solution to the black plotting area on OS X?

  1. #1
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question Qt 5.5.1 + QwtPlotDirectPainter = a solution to the black plotting area on OS X?

    Hi,

    I am currently working on upgrading Qt from version 5.4.2 to version 5.5.1 in my application. It's all working fine, except for a problem I am having with QwtPlotDirectPainter on OS X. That problem is the one I described here and here, i.e. that sometimes part of or all of the plotting area becomes black.

    Now, unlike in the first link where I tried to solve my problem by setting QwtPlotDirectPainter::FullRepaint to true, this time I decided to find out at what point, in the Qwt code, things go 'wrong'. Wrong in quotes because the problem might indeed be with Qt 5.5.1 and not Qwt as such, but the fact is that it's much easier and quicker to find out what goes 'wrong' in Qwt than in Qt.

    Anyway, the bottom line is that the 'problem' lies in QwtPlotDirectPainter::drawSeries(). Now, the fix that seems to be working consists of commenting out the installation/removal of an event filter (see here). I must confess that I don't quite understand the reason for that filter since such an event filter will always return false in the case of a canvas, or am I missing something? (Actually, I might since having that event filter does make things go 'wrong'!)

    Whatever the case, I am wondering my 'fix' is 'valid', 'acceptable'?

    Cheers, Alan.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 5.5.1 + QwtPlotDirectPainter = a solution to the black plotting area on OS X?

    Quote Originally Posted by agarny View Post
    I must confess that I don't quite understand the reason for that filter since such an event filter will always return false in the case of a canvas, or am I missing something?
    Starting with Qt4 it was not possible anymore ( beside for X11 graphics system, that is gone since Qt 5 ) to paint to a widget outside of a QWidget::paintEvent - because of how the Qt graphic stack is made. Of course this is the opposite of the idea of what QwtPlotDirectPainter is about. So this class is somehow doing things "against" how the Qt framework wants to have it.

    So on platforms, where Qt::WA_PaintOutsidePaintEvent is not supported QwtPlotDirectPainter sends an paint event to itself, that is caught by a temporary event filter. The code in the event filter is then running in the paint event context Qt is expecting to be valid, when painting to a widget.

    What your patch does is to disable the event filtering with the consequence, that the paint event goes in the normal event processing ( QwtPlotCanvas::paintEvent() ), where you run into a full repaint of the canvas. So the patch doesn't make too much sense as you would call canvas()->repaint() or probably QwtPlot::replot() for this.

    Unfortunately I don't have a Mac myself, but I would guess, that the problem is related to incremental painting - not to where it happens. If this is the case I can imagine, that using QwtPlotDirectPainter::FullRepaint in combination with QwtPlotCanvas::BackingStore is the best option as you still paint incrementally ( to the backing store ), but the widget is always repainted in the context Qt is expecting it.

    If you find out, that the problem is related to the fact, that rendering is done inside the event filter - not the paint event handler - you would at least have to implement some handling, that can identify the special type of paint event, where you simply have to draw some lines incrementally.

    But maybe you find out more than "guessing", when debugging what i going on on your Mac.

    Uwe

  3. #3
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 5.5.1 + QwtPlotDirectPainter = a solution to the black plotting area on OS X?

    Thanks a lot for the clarification, Uwe. I now understand the reasoning behind your use of a temporary event filter.

    Ok, here is what I have done next...

    I tried to use QwtPlotDirectPainter::FullRepaint in combination with QwtPlotCanvas::BackingStore, but although it's working fine on my development machine (OS X 10.11), it's not working as I would expect on OS X 10.8-10.10. Basically, if I try to plot 1,000,000 data points, then the plotting won't be smooth. Instead, I will get chunks of data points being plotted at once. So, it looks like I am getting some full repaints here and there.

    Next, and following your explanations, I re-enabled the temporary event filter and, indeed, this results in QwtPlotDirectPainter::eventFilter() being called for QEvent::Paint. However, as previously mentioned, this results in the plotting area becoming black on OS X. To comment out the return true; in QwtPlotDirectPainter::eventFilter() obviously 'fixes' the problem, but on OS X 10.8-10.10, it results in the issue mentioned in my previous paragraph, not to mention that not returning true obviously defeats the purpose of your temporary event filter! So, I put back return true; and then noticed the CopyBackingStore attribute. I therefore set it to true in my application and it's now all working fine and as I would expect, be it on my development machine or on a vanilla OS X 10.8-10.10 machine. I understand that having BackingStore set to true means slightly more work (i.e. always copying the backing store to the painter), but I guess that what matters to me at this point is that I now have a solution that not only seems to be working fine and as expected, but also makes sense to me (as opposed to last time where I was disabling the temporary event filter without really knowing why).

    In summary, thanks for putting me on the right track...

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 5.5.1 + QwtPlotDirectPainter = a solution to the black plotting area on OS X?

    Quote Originally Posted by agarny View Post
    I understand that having BackingStore set to true means slightly more work (i.e. always copying the backing store to the painter)
    The price you have to pay for this mode varies from platform to platform - f.e when running remote desktops it might be significant. Maybe it's worth to spend some time on clipping, it can do miracles.

    When adding a couple of points they often have a small bounding rectangle only. Using the canvas maps you can translate this rectangle into paint device coordinates and use it as clip region ( QwtPlotDirectPainter::setClipRegion ). Then only this parts of the pixmap will be copied to the graphics backend.

    I once did this for a device running QWS on top of an unaccelerated frame buffer. Copying 10 x 10 x sizeof(RGBA) only made a huge difference compared to copying 800 x 600 x sizeof(RGBA).

    Uwe

  5. #5
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 5.5.1 + QwtPlotDirectPainter = a solution to the black plotting area on OS X?

    When adding a couple of points they often have a small bounding rectangle only. Using the canvas maps you can translate this rectangle into paint device coordinates and use it as clip region ( QwtPlotDirectPainter::setClipRegion ). Then only this parts of the pixmap will be copied to the graphics backend.
    Thanks a lot for the suggestion, I am going to give QwtPlotDirectPainter::setClipRegion() a try.

Similar Threads

  1. Replies: 5
    Last Post: 16th July 2015, 08:44
  2. Replies: 0
    Last Post: 6th May 2014, 14:25
  3. QwtPlotPicker with QwtPlotDirectPainter
    By friendbaby in forum Qwt
    Replies: 1
    Last Post: 12th December 2012, 14:43
  4. Replies: 10
    Last Post: 1st April 2012, 08:55
  5. How to clear the plotting area?
    By cesroc in forum Qwt
    Replies: 1
    Last Post: 2nd March 2012, 15:37

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.