[Qt-interest] aspect-ratio for graphs

phil prentice philp.cheer at talktalk.net
Thu Jul 15 10:54:28 CEST 2010


Thanks Constantin
  QGraphicsScene & QGraphicsView look to me to enable you to managing a large 
number of 2D graphical items. I dont need that.  It uses scrollbars which 
again is not a requirement.  Thanks again for your input.
Phil

On Thursday 15 July 2010 08:27, Constantin Makshin wrote:
> Have you tried using QGraphicsScene and QGraphicsView to draw the graphs?
>
> On Thursday 15 July 2010 12:08:56 phil prentice wrote:
> > Thank you very much for your responses.
> >
> > 1) I have a commercial license for 4.2.1 and currently am stuck with that
> > version. So not sure about libqxt. I am running under Linux.
> >
> > 2) The graphs that I plan to display are going to be very simple and I
> > was planning simple to use paintEvent to do it. Axis + plotted points.
> >
> > 3) I thought that it should be fairly simply to get QT to draw a 1:1
> > aspect-ratio frame.  Obviously not.  Push come to shove I might have to
> > fix the frame sizes, but for a powerful GUI toolkit(+lots more) I will be
> > a little disappointed at that.
> >
> > 4) I will cut down my code and see if I can get anywhere using
> > setSizePolicy() and heightForWidth() just in case I can get them to work.
> >
> > Thank you very much for all your help
> >
> > Phil
> >
> > On Wednesday 14 July 2010 18:41, Christian Gagneraud wrote:
> > > On 07/14/2010 07:31 PM, Jason H wrote:
> > > > Check out libqxt. They have an AR aware widget, that you can put your
> > > > graph in.
> > >
> > > Did you have a look at qwt?
> > >
> > > "The Qwt library contains GUI Components and utility classes which are
> > > primarily useful for programs with a technical background [...]"
> > > They have lot of widgets for plots, knobs, sliders, ...
> > >
> > > http://qwt.sourceforge.net
> > >
> > > Chris
> > >
> > > > ----- Original Message ----
> > > > From: phil prentice<philp.cheer at talktalk.net>
> > > > To: qt-interest at trolltech.com
> > > > Sent: Wed, July 14, 2010 12:57:06 PM
> > > > Subject: [Qt-interest] aspect-ratio for graphs
> > > >
> > > > Hi
> > > >    I am sorry to say that I think that this question has been asked a
> > > > few times before, with varying answers.  I am trying to draw six
> > > > graphs side by side with a number of widgets displayed below it.  I
> > > > am using horizontal and vertical layouts to do this.  And yes I would
> > > > like to force the aspect ratio of the graphs to be 1:1.  Reading
> > > > various qt-interest forum answers it seemed to suggest that I could
> > > > use the member functions setSizePolicy() and heightForWidth()...which
> > > > I have tried to do with no success.
> > > > Is the general principle of what I am trying to do correct? Any ideas
> > > > as to why it does not work for me?
> > > >
> > > > Any help would be welcome....I love QT but sometimes its just too
> > > > hard!!!
> > > >
> > > > Thanks
> > > > Phil
> > > >
> > > > I have defined a class called VIgraph() derived from QFrame() i.e.
> > > > VIgraph::VIgraph(QWidget *parent, Qt::WindowFlags f):QFrame(parent,f)
> > > > {
> > > >    // Create a frame around the graphs.
> > > >    setFrameStyle(QFrame::Box|QFrame::Plain);
> > > >    QSizePolicy policy(QSizePolicy::Preferred,
> > > > QSizePolicy::Preferred); policy.setHeightForWidth(true);  // Keep
> > > > aspect ratio
> > > >    setSizePolicy(policy);
> > > > }
> > > >
> > > > int VIgraph::heightForWidth(int w) const
> > > > {
> > > >    if(height()>  w)
> > > >      return w;
> > > >    else
> > > >      return height();
> > > > }
> > > >
> > > > My main window widget creates various widgets(including the VIgraph
> > > > widgets) and lays them out (see two following functions)
> > > >
> > > > void VIwindow::createWidgets()
> > > > {
> > > >    int i;
> > > >
> > > >    // Create the 6 graphs, the 6 labeled Pass/Fail labels and the 6
> > > > checkboxes. for(i = 0; i<  6; i++)
> > > >    {
> > > >      m_graph[i] = new VIgraph();
> > > >      m_graphPassFailLabel[i] = new QLabel();
> > > >      m_graphPassFailTextLabel[i] = new
> > > > QLabel(QString("VI%1Pass/Fail").arg(i)); m_graphCheckBoxs[i] = new
> > > > QCheckBox(QString("Select VI%1").arg(i)); }
> > > >    // Create Tolerance slider and tolerance checkbox along with
> > > > label. m_toleranceSlider = new QSlider(Qt::Horizontal);
> > > >    m_toleranceLineEdit = new QLineEdit();
> > > >    m_toleranceCheckBox = new QCheckBox("View Tolerance");
> > > >    // Create Save&  Cancel pushbuttons.
> > > >    m_saveToleranceButton = new QPushButton(tr("Save Tol"));
> > > >    m_cancelToleranceButton = new QPushButton(tr("Cancel"));
> > > >    // Auto/Manual Combi-box.
> > > >    m_autoManualComboBox = new QComboBox();
> > > >    m_autoManualComboBox->addItem("Auto");
> > > >    m_autoManualComboBox->addItem("Manual");
> > > > // Single-shot&  Continuous pushbuttons.
> > > >    m_singleShotButton = new QPushButton(tr("Single Shot"));
> > > >    m_continuousButton = new QPushButton(tr("Continuous"));
> > > >
> > > >    // Set fixed widgets attributes.
> > > >    m_toleranceLineEdit->setReadOnly(true);
> > > >    m_toleranceSlider->setMinimum(0);
> > > >    m_toleranceSlider->setMaximum(100);
> > > >    m_toleranceSlider->setTickInterval(1);
> > > >
> > > >    QPixmap greyPixmap(":resources/images/greyButton.png"); // Default
> > > > pixmap QSize max(16, 16);
> > > >    for(i = 0; i<  6; i++)
> > > >    {
> > > >      m_graphPassFailLabel[i]->setPixmap(greyPixmap);
> > > >      // Set Label sizes and scale the contents.
> > > >      m_graphPassFailLabel[i]->setMaximumSize(max);
> > > >      m_graphPassFailLabel[i]->setScaledContents(true);
> > > >    }
> > > > ]
> > > >
> > > > void VIwindow::doLayout()
> > > > {
> > > >    int i;
> > > >
> > > >    // Create Pass/Fail label with text as horizontal layout.
> > > >    QHBoxLayout *passFailLayout[6];
> > > >    for(i = 0; i<  6; i++)
> > > >    {
> > > >      passFailLayout[i] = new QHBoxLayout;
> > > >      passFailLayout[i]->addWidget(m_graphPassFailLabel[i]);
> > > >      passFailLayout[i]->addWidget(m_graphPassFailTextLabel[i]);
> > > >      passFailLayout[i]->addStretch();
> > > >    }
> > > >    // Create the six vertical graph layouts with label.
> > > >    QVBoxLayout *graphLayout[6];
> > > >    for(i = 0; i<  6; i++)
> > > >    {
> > > >      graphLayout[i] = new QVBoxLayout;
> > > >      graphLayout[i]->addWidget(m_graph[i]);       // Aspect-ratio
> > > > needed. graphLayout[i]->addLayout(passFailLayout[i]);
> > > >    }
> > > >
> > > >    // Plonk all graph layouts into one horizontal layout.
> > > >    QHBoxLayout *firstRowLayout = new QHBoxLayout;
> > > >    for(i = 0; i<  6; i++)
> > > >    {
> > > >      firstRowLayout->addLayout(graphLayout[i]);
> > > >    }
> > > >    // Layout the checkbox row to follow.
> > > >    QHBoxLayout *secondRowLayout = new QHBoxLayout;
> > > >    for(i = 0; i<  6; i++)
> > > >    {
> > > >      secondRowLayout->addWidget(m_graphCheckBoxs[i]);
> > > >    }
> > > >    // Layout the tolerance row.
> > > >    QHBoxLayout *thirdRowLayout = new QHBoxLayout;
> > > >    thirdRowLayout->addWidget(m_toleranceSlider);
> > > >    thirdRowLayout->addWidget(m_toleranceLineEdit);
> > > >    thirdRowLayout->addWidget(m_toleranceCheckBox);
> > > >    thirdRowLayout->addWidget(m_saveToleranceButton);
> > > >    thirdRowLayout->addWidget(m_cancelToleranceButton);
> > > >
> > > >    // Layout the auto/manual and single-shot buttons.
> > > >    QHBoxLayout *fourthRowLayout = new QHBoxLayout;
> > > >    fourthRowLayout->addStretch();
> > > >    fourthRowLayout->addWidget(m_autoManualComboBox);
> > > >    fourthRowLayout->addWidget(m_singleShotButton);
> > > >    fourthRowLayout->addWidget(m_continuousButton);
> > > >
> > > >    // Do Top layout.
> > > >    QVBoxLayout *topLayout = new QVBoxLayout;
> > > >    topLayout->addLayout(firstRowLayout);
> > > >    topLayout->addLayout(secondRowLayout);
> > > >    topLayout->addLayout(thirdRowLayout);
> > > >    topLayout->addLayout(fourthRowLayout);
> > > >
> > > >    QWidget *dummy = new QWidget();
> > > >    dummy->setLayout(topLayout);
> > > >    setCentralWidget(dummy);
> > > > }
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest



More information about the Qt-interest-old mailing list