Results 1 to 16 of 16

Thread: Need to resize the window to make QwtPlotSpectrogram shows correctly

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Need to resize the window to make QwtPlotSpectrogram shows correctly

    What does "Qt::WA_WState_Polished" mean ?
    It is an attribute, that is set once the widget has received a QEvent::Polish event - see https://doc.qt.io/qt-5/qwidget.html#ensurePolished.

    A widget always gets an initial resize event that leads in case of the plot widget to calling updateLayout and there is no reason to trigger extra updates before that. So checking for Qt::WA_WState_Polished is a minor optimization for this initial phase.

    what do you think about the fact that I need to set an expanding vertical and horizontal size policy for the QwtPlot which is a child of another QWidget so that the QwtPlot takes all the available space
    A widget doesn't take any space it is always the parent that gives its children their geometries. So obviously your parent widget does this according to the size policies of its children. The default size policy of the plot widget is QSizePolicy::MinimumExpanding in both directions - why your parent does what it does then is hard to say without knowing your code.

    Uwe

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

    embeddedmz (23rd June 2019)

  3. #2
    Join Date
    Jan 2020
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Need to resize the window to make QwtPlotSpectrogram shows correctly

    Hi all, first post in the forum. I had the same resize problem as the OP.

    I wanted to show a bar plot:

    Qt Code:
    1. BarChart::BarChart(QWidget *parent) :
    2. QwtCustomPlot(parent)
    3. {
    4. QwtColumnSymbol *columnSymbol;
    5.  
    6. columnSymbol = new QwtColumnSymbol(QwtColumnSymbol::Box);
    7. columnSymbol->setLineWidth(0);
    8. columnSymbol->setFrameStyle(QwtColumnSymbol::NoFrame);
    9. columnSymbol->setPalette(QPalette("Red"));
    10.  
    11. _barChart = new QwtPlotBarChart();
    12. _barChart->setLayoutPolicy(QwtPlotBarChart::AutoAdjustSamples);
    13. _barChart->setSpacing(2);
    14. _barChart->setMargin(0);
    15. _barChart->setSymbol(columnSymbol);
    16. _barChart->attach(this);
    17.  
    18. setAxisAutoScale(QwtPlot::yLeft);
    19. }
    To copy to clipboard, switch view to plain text mode 

    inherited from the custom plotter

    Qt Code:
    1. QwtCustomPlot::QwtCustomPlot(QWidget *parent) :
    2. QwtPlot(parent)
    3. {
    4. ((QFrame *)canvas())->setLineWidth(0);
    5. ((QFrame *)canvas())->setFrameStyle(QFrame::NoFrame);
    6. ((QFrame *)canvas())->setPalette(QColor("White"));
    7.  
    8. plotLayout()->setCanvasMargin(0);
    9.  
    10. setAttribute(Qt::WA_Hover);
    11.  
    12. setAutoFillBackground(true);
    13. enableAxis(QwtPlot::xBottom, false);
    14. enableAxis(QwtPlot::yLeft, false);
    15.  
    16. QwtText axisText;
    17. axisText.setFont(QApplication::font());
    18.  
    19. setAxisTitle(QwtPlot::xBottom, axisText);
    20. setAxisTitle(QwtPlot::yLeft, axisText);
    21. setAxisFont(QwtPlot::xBottom, QApplication::font());
    22. setAxisFont(QwtPlot::yLeft, QApplication::font());
    23. }
    To copy to clipboard, switch view to plain text mode 

    which sets the canvas margin to 0, hence filling the canvas with the bar plot.
    Since a bar is 1 unit wide, the x axis range of n bars goes from -0.5 to n-0.5. I scale it manually at each update:

    Qt Code:
    1. void BarChart::setBars(const QVector<double> &values)
    2. {
    3. if(values.isEmpty())
    4. return;
    5.  
    6. setAxisScale(
    7. QwtPlot::xBottom,
    8. -0.5,
    9. values.size()-0.5);
    10.  
    11. _barChart->setSamples(values);
    12. }
    To copy to clipboard, switch view to plain text mode 

    This works as long as I don't resize the plot, with the bar at the extremes adjacent to the widget border.
    However, resizing the plot resets the canvas margins to 0.5 units to the extremes, hence changing the layout.

    The solution was to force the canvas margins to follow the scale

    Qt Code:
    1. plotLayout()->setAlignCanvasToScales(true);
    To copy to clipboard, switch view to plain text mode 

    The resize now keeps the layout unaltered!

Similar Threads

  1. How to make a user not resize a window.
    By marcos.miranda in forum Newbie
    Replies: 2
    Last Post: 20th September 2017, 22:23
  2. Replies: 0
    Last Post: 8th June 2012, 14:27
  3. Replies: 0
    Last Post: 7th June 2012, 22:58
  4. Widget does not resize correctly
    By Demandred in forum Newbie
    Replies: 4
    Last Post: 16th April 2010, 13:06
  5. Program that just shows a window
    By claudio-cit in forum Newbie
    Replies: 2
    Last Post: 5th July 2008, 10:55

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.