Results 1 to 6 of 6

Thread: setAxisScale become invalid to xTop Axis?

  1. #1
    Join Date
    Jan 2014
    Posts
    16
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default setAxisScale become invalid to xTop Axis?

    hi, all.
    i meet a problem with setAxisScale . when i use setAxisScale to set xTop axis , it can't work as i expect ,however , when i set xBottom , it works fine..

    I try to change the curve by setting the xTop axis ,but the curve can't change! the code is as follow:

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    ui->qwtPlot->setCanvasBackground( Qt::white );

    ui->qwtPlot->enableAxis(QwtPlot::xBottom,false);
    ui->qwtPlot->enableAxis(QwtPlot::xTop,true);

    ui->qwtPlot->setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
    ui->qwtPlot->setAxisScale( QwtPlot::xTop, 0.0, 10.0 );


    QwtPlotCurve *curve= new QwtPlotCurve();

    curve->setPen( Qt::blue );
    curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );

    QPolygonF points;
    points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
    << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
    << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
    curve->setSamples( points );

    curve->attach(ui->qwtPlot);


    ui->qwtPlot->resize( 600, 400 );
    }


    however . i can set the xBottom AXIS scale and th program works well, the key part of code is as follow:

    //ui->qwtPlot->enableAxis(QwtPlot::xBottom,false);
    //ui->qwtPlot->enableAxis(QwtPlot::xTop,true);

    ui->qwtPlot->setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
    ui->qwtPlot->setAxisScale( QwtPlot::xBottom, 0.0, 100.0 );


    i want to know a way to set the xTop axis scale correctly ,can u help me?

    Micky Jhon.

  2. #2
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Thanked 16 Times in 15 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: setAxisScale become invalid to xTop Axis?

    it can't work as i expect
    Run the code below... Are the scales drawn as expected?

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4.  
    5. QwtPlot plot;
    6.  
    7. plot.setCanvasBackground( Qt::white );
    8.  
    9. plot.enableAxis(QwtPlot::xBottom,false);
    10. plot.enableAxis(QwtPlot::xTop,true);
    11.  
    12. plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
    13. plot.setAxisScale( QwtPlot::xTop, 0.0, 10.0 );
    14.  
    15. QwtPlotCurve *curve= new QwtPlotCurve();
    16.  
    17. curve->setPen( Qt::blue );
    18. curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
    19.  
    20. QPolygonF points;
    21. points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
    22. << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
    23. << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
    24. curve->setSamples( points );
    25. curve->attach(&plot);
    26. plot.resize( 600, 400 );
    27.  
    28. plot.show();
    29.  
    30. return a.exec();
    31. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Cah for this useful post:

    MickyJhon (26th January 2014)

  4. #3
    Join Date
    Jan 2014
    Posts
    16
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: setAxisScale become invalid to xTop Axis?

    test1.JPG, sorry, the problem is still, and the result is wrong! it looks like setAxisScale function is invalid to xTop? please help me.
    Quote Originally Posted by Cah View Post
    Run the code below... Are the scales drawn as expected?

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4.  
    5. QwtPlot plot;
    6.  
    7. plot.setCanvasBackground( Qt::white );
    8.  
    9. plot.enableAxis(QwtPlot::xBottom,false);
    10. plot.enableAxis(QwtPlot::xTop,true);
    11.  
    12. plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
    13. plot.setAxisScale( QwtPlot::xTop, 0.0, 10.0 );
    14.  
    15. QwtPlotCurve *curve= new QwtPlotCurve();
    16.  
    17. curve->setPen( Qt::blue );
    18. curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
    19.  
    20. QPolygonF points;
    21. points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
    22. << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
    23. << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
    24. curve->setSamples( points );
    25. curve->attach(&plot);
    26. plot.resize( 600, 400 );
    27.  
    28. plot.show();
    29.  
    30. return a.exec();
    31. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,253
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setAxisScale become invalid to xTop Axis?

    The coordinate systems spanned by the 4 axes are always present - independent from the visibility of an axis. A plot item is always related to one x/y combination, different plot items on the same plot might be related to different combinations ( see the bode example, where you have 2 y axes ). In your code the curve is related to the invisible xBottom scale - because xBottom/yleft is the default setting.

    The following line is missing:

    Qt Code:
    1. curve->setXAxis( QwtPlot::xTop ):
    To copy to clipboard, switch view to plain text mode 
    Uwe

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

    MickyJhon (26th January 2014)

  7. #5
    Join Date
    Jan 2014
    Posts
    16
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: setAxisScale become invalid to xTop Axis?

    thank you very much,that's the answer!
    Quote Originally Posted by Uwe View Post
    The coordinate systems spanned by the 4 axes are always present - independent from the visibility of an axis. A plot item is always related to one x/y combination, different plot items on the same plot might be related to different combinations ( see the bode example, where you have 2 y axes ). In your code the curve is related to the invisible xBottom scale - because xBottom/yleft is the default setting.

    The following line is missing:

    Qt Code:
    1. curve->setXAxis( QwtPlot::xTop ):
    To copy to clipboard, switch view to plain text mode 
    Uwe

  8. #6
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Thanked 16 Times in 15 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: setAxisScale become invalid to xTop Axis?

    Yes

    Thanks

Similar Threads

  1. invalid QModelIndex
    By Talei in forum Newbie
    Replies: 1
    Last Post: 18th January 2010, 21:21
  2. setAxisScale(1) doesn't do anything
    By rakkar in forum Qwt
    Replies: 1
    Last Post: 19th September 2009, 11:42
  3. SetAxisScale problem
    By emrares in forum Qwt
    Replies: 2
    Last Post: 12th August 2009, 18:45
  4. QDateTime Invalid
    By FreePascal in forum Newbie
    Replies: 2
    Last Post: 7th June 2009, 20:35
  5. intersectingStaticSet: row 'x' was invalid
    By Kumosan in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2007, 16:41

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.