Results 1 to 10 of 10

Thread: QWtPlot: Workaround for insertLegend bug?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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?

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    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

  3. #3
    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)

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    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

  5. 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
  •  
Qt is a trademark of The Qt Company.