Results 1 to 8 of 8

Thread: PyQt4 PyQwt5 Windows 7 - Plot size problem

  1. #1
    Join Date
    Aug 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    Default PyQt4 PyQwt5 Windows 7 - Plot size problem

    I have the rudimentary beginning of a Gui for an oscilloscope.
    Using 4 group boxes, with the plot in the top left box, and
    3 other boxes for controls.

    I can not get the plot to automatically fill the group box horizontally,
    although it fits the box vertically automatically.

    After searching other examples, I found #set axis scales.
    Juggling the 3 lines, I can get the plot to fill the box.

    Since I want to be able to select different scales, that means
    that I would have to change the axis settings every time.

    Also, I set MainWindow to be 800x800, but changing the axis scales,
    and setAxisMajor, also changes the main window size.

    Obviously, I am missing something.

    Qt Code:
    1. self.setCanvasBackground(Qt.Qt.black)
    2. self.plotLayout().setMargin(0)
    3. self.plotLayout().setCanvasMargin(0)
    4. self.plotLayout().setAlignCanvasToScales(False)
    5.  
    6. grid = Qwt.QwtPlotGrid()
    7. grid.attach(self)
    8. grid.setPen(Qt.QPen(Qt.Qt.white, 0, Qt.Qt.DotLine))
    9.  
    10. # set axis titles
    11. self.setAxisTitle(Qwt.QwtPlot.xBottom, 'Time (usec)')
    12. self.setAxisTitle(Qwt.QwtPlot.yLeft, 'Amplitude (V)')
    13.  
    14. # set axis scales
    15. self.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, 10.0)
    16. self.setAxisScale(Qwt.QwtPlot.yLeft, -2.0, 2.0)[ATTACH=CONFIG]8606[/ATTACH]
    17. self.setAxisMaxMajor(Qwt.QwtPlot.xBottom, 25);
    18.  
    19. scaleDraw = self.axisScaleDraw(Qwt.QwtPlot.yLeft)
    20. scaleDraw.setMinimumExtent(scaleDraw.extent(
    21. Qt.QPen(), self.axisWidget(Qwt.QwtPlot.yLeft).font()))
    To copy to clipboard, switch view to plain text mode 

    Don












































    after more experimentation,
    Attached Images Attached Images

  2. #2
    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: PyQt4 PyQwt5 Windows 7 - Plot size problem

    Juggling the 3 lines, I can get the plot to fill the box.
    Do you mean "curve", when you say "plot", "box" might be the "canvas" and by "filling the box" you mean that the range of the x-axis should be adjusted to the bounding rectangle of the curve ?
    Also, I set MainWindow to be 800x800, but changing the axis scales,
    and setAxisMajor, also changes the main window size..
    Do you mean the plot widget by "main window" ?

    Please repeat your question using another terminology:


    • plot widget
    • canvas
    • curve
    • axis/scale


    Uwe

  3. #3
    Join Date
    Aug 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    Default Re: PyQt4 PyQwt5 Windows 7 - Plot size problem

    Quote Originally Posted by Uwe View Post
    Do you mean "curve", when you say "plot", "box" might be the "canvas" and by "filling the box" you mean that the range of the x-axis should be adjusted to the bounding rectangle of the curve ?

    Do you mean the plot widget by "main window" ?

    Please repeat your question using another terminology:


    • plot widget
    • canvas
    • curve
    • axis/scale


    Uwe
    I have the rudimentary beginning of a Gui for an oscilloscope.
    Using 4 group boxes, with the plot Widget in the top left group box, and
    3 other group boxes for controls.

    I can not get the canvas to automatically fill the group box horizontally,
    although it fits the group box vertically automatically.

    After searching other examples, I found #set axis scales.
    Juggling the 3 lines, I can get the canvas to fill the box.

    Since I want to be able to select different axis scales, (for instance 0 to 1 volt, or 0-5 volts, etc) that means
    that I would have to change the axis settings every time.

    Also, I set class MainWindow to be 800x800, by self.resize(800, 800), but changing the axis scales,
    and setAxisMajor, also changes the main window size.

    Also, see the jpg which , for some reason, you have to scroll down to see.

    I hope that this is clearer, and thanks for helping with the terminology,
    Don

  4. #4
    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: PyQt4 PyQwt5 Windows 7 - Plot size problem

    Quote Originally Posted by dayo30 View Post
    I can not get the canvas to automatically fill the group box horizontally,
    although it fits the group box vertically automatically.
    The canvas is a child of the plot widget, that is a child of your group box. So when this is about, that the plot widget is not resized according to the group box the problem is unrelated to Qwt and should be a problem of your layout. Note that QwtPlot is a QWidget and for QLayoutsthere is nothing special with it compared to other widgets.
    Quote Originally Posted by dayo30 View Post
    After searching other examples, I found #set axis scales.
    Juggling the 3 lines, I can get the canvas to fill the box.
    Sorry but this statement doesn't make more sense: the canvas is resized together with the plot widget, what is completely unrelated to the scales. The only effect on the layout you might have is, that the sizeHint() of the plot widget depends on the space that is needed for the tick labels.

    Quote Originally Posted by dayo30 View Post
    Also, see the jpg which , for some reason, you have to scroll down to see.
    In the screenshot I can see a plot widget that is perfectly aligned in a group box and a canvas that is perfectly aligned to its plot widget. On the canvas I can see a curve with a bounding range [ 0 - 3 ] displayed on a coordinate system with a range of [ 0 - 20 ]. This all has nothing to to do with "canvas not filling a group box".

    Isn't your problem simply, that you want a coordinate system with a range according to the range of the curve ?

    Uwe

  5. #5
    Join Date
    Aug 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    Default Re: PyQt4 PyQwt5 Windows 7 - Plot size problem

    Quote Originally Posted by Uwe View Post
    The canvas is a child of the plot widget, that is a child of your group box. So when this is about, that the plot widget is not resized according to the group box the problem is unrelated to Qwt and should be a problem of your layout. Note that QwtPlot is a QWidget and for QLayoutsthere is nothing special with it compared to other widgets.

    Sorry but this statement doesn't make more sense: the canvas is resized together with the plot widget, what is completely unrelated to the scales. The only effect on the layout you might have is, that the sizeHint() of the plot widget depends on the space that is needed for the tick labels.


    In the screenshot I can see a plot widget that is perfectly aligned in a group box and a canvas that is perfectly aligned to its plot widget. On the canvas I can see a curve with a bounding range [ 0 - 3 ] displayed on a coordinate system with a range of [ 0 - 20 ]. This all has nothing to to do with "canvas not filling a group box".

    Isn't your problem simply, that you want a coordinate system with a range according to the range of the curve ?

    Uwe
    Well, the "plot widget that is perfectly aligned in a group box and a canvas that is perfectly aligned to its plot widget" is because, as I stated earlier, I juggled the 3 "axis" statements to make it look that way. Also, as I mentioned, the canvas aligns properly, vertically, with the group box, at what ever setting of
    self.setAxisScale(Qwt.QwtPlot.yLeft,.

    To get the canvas to fill the group box horizontally, I had to add the line self.setAxisMaxMajor(Qwt.QwtPlot.xBottom,.
    This, however, does not allow me to use whatever x axis scale that I want. There is something missing here.

    I have a new screenshot, with x axis 10, and "self.setAxisMaxMajor(Qwt.QwtPlot.xBottom, 20)" commented out.
    Note that the canvas does not fill the group box horizontally, and also that the when this is the case, the main
    window retains its 800x800 size. Note: the combo box settings are not yet connected.

    # set axis scales
    self.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, 10, 1)
    self.setAxisScale(Qwt.QwtPlot.yLeft, -2.0, 2.0)
    # self.setAxisMaxMajor(Qwt.QwtPlot.xBottom, 20)

    Plot.jpg

  6. #6
    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: PyQt4 PyQwt5 Windows 7 - Plot size problem

    This issue is more or less unrelated to Qwt: read about QLayout, QWidget::sizeHint(), QWidget::sizePolicy(). Guess you are doing something wrong when inserting the plot into the layout of the group box.

    The reason why you see an effect with modifying the scales is because the number of tick labels have an impact on the sizeHint() of the plot.

    Uwe

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

    dayo30 (23rd January 2013)

  8. #7
    Join Date
    Aug 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    Default Re: PyQt4 PyQwt5 Windows 7 - Plot size problem

    I guess that I will have to try to understand the Qwt classes.
    I have tried to use the Qwt User's Guide, but can not seem to figure them out, in relation to Py4Qwt
    Is there some kind of documentation that one needs to study before it is clear?

    Anyway, I thank you very much for attempting to sort this out for me.

    Don

  9. #8
    Join Date
    Aug 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    Default Re: PyQt4 PyQwt5 Windows 7 - Plot size problem

    Uwe,

    The reason why you see an effect with modifying the scales is because the number of tick labels have an impact on the sizeHint() of the plot.
    This was the hint that I needed!
    All that I will need to do, is to have "if" statements to configure the axis scales, based on signals from the combo boxes,
    to get the canvas to always be the same size.

    So, on to figuring out how to do this. :-)

    Thanks again for your patience,
    Don

Similar Threads

  1. Cross-platform Windows & Mac: Font size problem
    By monkazer in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2012, 16:10
  2. Creating popup windows pyqt4
    By jaybstory in forum Newbie
    Replies: 1
    Last Post: 9th April 2011, 22:15
  3. Windows Mobile VGA Screen font size problem
    By LordG in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 25th November 2010, 10:13
  4. PyQt4 signals not working on windows xp
    By eltazar in forum Newbie
    Replies: 2
    Last Post: 29th July 2010, 17:40
  5. Drag pixmap on Windows size problem
    By plamkata in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2009, 00:01

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.