Results 1 to 10 of 10

Thread: QWtPlot: Workaround for insertLegend bug?

  1. #1
    Join Date
    Dec 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default QWtPlot: Workaround for insertLegend bug?

    Could someone post me solution for such bug?
    Qt Code:
    1. QwtLegend *legend = new QwtLegend();
    2. qwtPlot->insertLegend(legend, QwtPlot::RightLegend);
    To copy to clipboard, switch view to plain text mode 
    this is only difference between good / bad look.
    Code is simple - new Plot
    insert legend
    other things arn't important ( bug still exist with commented rest of code )
    qwt: 5.2.1
    qt 4.5
    compiler: vc2008
    Attached Images Attached Images

  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: QWtPlot: Workaround for insertLegend bug?

    Hard to say what is wrong - but it looks like the layout has not been recalculated and the left scale widget is smaller than its scale.

    Guess you insert your legend later - when the plot is already visible - and the problem is gone, when you call QwtPlot::updateLayout() or manually resize the plot with the mouse.

    Please post your code demonstrating the bug.

    Uwe

  3. #3
    Join Date
    Dec 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWtPlot: Workaround for insertLegend bug?

    As I said there's no need more code - QwtPlot is create by Designer and in parent constructor ( after setupUI ) I call new legend, insertLegend
    call updateLayout() in this place replot or similiar is without effect.
    of course after display plot and resize it bad effect is gone - but it's not a solution, I have to show it fine in first view.
    Some part of solution could be set
    Qt Code:
    1. qwtPlot->setAutoReplot();
    To copy to clipboard, switch view to plain text mode 
    but with such set QwtPlot get bigger ( about legend size ) and mess other view with grid layout which holds Widgets with plots.
    setAutoReplot to true - false - don't work
    Is there other ( better ) function to recalculate qwtPlot ??

    Ok I found workaround by call updateLayout but just before display main widget
    Last edited by darkshu; 7th December 2010 at 08:20.

  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: QWtPlot: Workaround for insertLegend bug?

    The code you have posted is used in many applications ( f.e Qwt examples ) without any problems - so there has to be something special in your code. But when you insist on not posting code ...

    Uwe

  5. #5
    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: QWtPlot: Workaround for insertLegend bug?

    The code you have posted is used in many applications ( f.e Qwt examples ) without any problems - so there has to be something special in your code. But when you insist on not posting code ...

    Uwe

  6. #6
    Join Date
    Dec 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWtPlot: Workaround for insertLegend bug?

    If example is simple the same code may work fine and with other code it could crash - but bug is in that code.
    I think I 've got it becauce i put QwtPlot into QDockWidget and that in QGridLayout
    if you really need code is something like that:
    Qt Code:
    1. q = new QwtPlot();
    2. dw = new QDockWidget();
    3. dw->setWidget(q)
    4. l = new QGridLayout(this)
    5. l->addWidget(dw)
    To copy to clipboard, switch view to plain text mode 
    if there is legend q probably catch some event inproperly

  7. #7
    Join Date
    Dec 2010
    Posts
    10
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWtPlot: Workaround for insertLegend bug?

    I have the same problem as darkshu. Actually it is really strange because I have a several plots in a few widgets. All the widgets look ok except one. And I can't understand what is wrong (unusual) with that one.
    Does anybody know why the problem can appear and how to fix it?

  8. #8
    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: QWtPlot: Workaround for insertLegend bug?

    The same answer: if you want to look into this, send me a small compilable application demonstrating the problem.

    Uwe

  9. #9
    Join Date
    Dec 2010
    Posts
    10
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWtPlot: Workaround for insertLegend bug?

    I found where was a problem but I didn't understand why it was so.

    Here is a demostration example:

    A Qwt plot with a legend
    Qt Code:
    1. class SimplePlot : public QwtPlot{
    2.  
    3. public:
    4.  
    5. SimplePlot ();
    6. SimplePlot (QWidget * widget);
    7. };
    8.  
    9. SimplePlot::SimplePlot() {
    10.  
    11. QwtLegend *legend = new QwtLegend(this);
    12. insertLegend(legend, QwtPlot::RightLegend);
    13. }
    14.  
    15. SimplePlot::SimplePlot (QWidget * widget) : QwtPlot (widget){
    16.  
    17. QwtLegend *legend = new QwtLegend(this);
    18. insertLegend(legend, QwtPlot::RightLegend);
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    A code with a bug:
    Qt Code:
    1. QTabWidget * tabWidget = new QTabWidget;
    2. QWidget * plotWidget = new QWidget;
    3. SimplePlot * plot = new SimplePlot (plotWidget); // a problem
    4. //SimplePlot * plot = new SimplePlot; // no problems
    5.  
    6. QVBoxLayout * plotLayout = new QVBoxLayout;
    7. plotLayout->addWidget(plot);
    8. plotWidget->setLayout(plotLayout);
    9.  
    10. tabWidget->insertTab(0, new QLabel(), "Test Label");
    11. tabWidget->insertTab(1, plotWidget, "Plot");
    12.  
    13. tabWidget->setMinimumSize(400, 400);
    14. tabWidget->show();
    To copy to clipboard, switch view to plain text mode 

    P.S. if I firstly insert the "Plot" tab and secondly the "Test Label" tab everything also looks fine (even if I use a constructor with a parent widget)

  10. #10
    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: QWtPlot: Workaround for insertLegend bug?

    When the plot is initially on a hidden tab it gets a polish request in a hidden state and the resize event later before it gets displayed ( what could be considered as a Qt bug ). In such a situation the plot layout gets calculated for the widget default size ( 100x30 ) with an invalid height for the vertical scales. The QwtPlot layout code can't handle this with the result, that can be seen on your screenshot.

    To avoid this problem I set a default size of 200x200 in the constructor to have something valid, when the polish request is processed. Note, that you will never see the plot widget in its default size, as its size is always changed by your application layout before it gets visible.

    The fix is in SVN ( 5.2 + trunk branches ). If you don't want to update your installed Qwt version you can simply do this in your application code:

    Qt Code:
    1. QwtPlot *plot = new QwtPlot( ...);
    2. plot->resize( 200, 200 );
    3. ...
    To copy to clipboard, switch view to plain text mode 
    Uwe

  11. The following user says thank you to Uwe for this useful post:

    AnnaP (14th February 2011)

Similar Threads

  1. workaround for messagebox modality bug
    By mortoray in forum Qt Programming
    Replies: 1
    Last Post: 17th October 2010, 11:07
  2. Workaround for a Qt ui bug
    By eurodatar in forum Qt Programming
    Replies: 2
    Last Post: 8th July 2010, 16:12
  3. Workaround for StandardItemModel drag drop bug
    By onamatic in forum Qt Programming
    Replies: 4
    Last Post: 9th November 2008, 21:50
  4. QWidget::setMask: bug &/or help for workaround
    By ataffard in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2008, 07:34
  5. Replies: 13
    Last Post: 1st October 2006, 17:02

Tags for this Thread

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.