Results 1 to 2 of 2

Thread: Maintaining square widget (plot)

  1. #1
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default Maintaining square widget (plot)

    Hi,

    Is there a way to maintain QwtPlot's physical aspect ratio in a layout? Uwe, you suggested QwtPlotRescaler before, but now I need QwtPlot to look like a square widget instead of rectangle when the window stretches. Here's what I tried to do:

    Qt Code:
    1. TargetDisplay::TargetDisplay(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. ui.setupUi(this);
    5. d_plot = new RandomPlot(this);
    6.  
    7. QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    8. policy.setHeightForWidth(true);
    9. d_plot->setSizePolicy(policy);
    10.  
    11. ui.horizontalLayout->insertWidget(0, d_plot);
    12. }
    To copy to clipboard, switch view to plain text mode 

    and then in my RandomPlot widget I have:

    Qt Code:
    1. class RandomPlot: public IncrementalPlot
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. RandomPlot(QWidget *parent);
    7. ~RandomPlot();
    8.  
    9. int heightForWidth(int w) const {
    10. return w;
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    But it's not remaining a square whenever the window stretches. What else do I need to include? Thank you.

    -James

  2. #2
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default Re: Maintaining square widget (plot)

    Nevermind, I figured it out. Instead of adding d_plot directly to the horizontalLayout, I added it to QwtDynGridLayout first, and then added the layout to the horizontalLayout:

    Qt Code:
    1. gLayout = new QwtDynGridLayout(this);
    2. gLayout->addWidget(d_plot);
    3. ui.horizontalLayout->insertLayout(0, gLayout);
    To copy to clipboard, switch view to plain text mode 

    Now I get a square

Similar Threads

  1. Qwt : 2 plot on the same widget
    By giusepped in forum Qwt
    Replies: 2
    Last Post: 11th April 2010, 19:10
  2. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  3. keeping a widget to be square
    By jmsbc in forum Qt Programming
    Replies: 5
    Last Post: 16th June 2009, 19:47
  4. Creating a square sized widget in a layout
    By cboles in forum Qt Programming
    Replies: 5
    Last Post: 22nd September 2008, 23:38
  5. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35

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.