Results 1 to 2 of 2

Thread: QwtScaleDraw align label to xaxis

  1. #1
    Join Date
    Oct 2010
    Posts
    58
    Thanks
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default QwtScaleDraw align label to xaxis

    Hi,

    I'm making a qwtplot and I am setting the xaxis with some dates using QwtScaleDraw, I have a few questions about the implementation.

    First, when I load the data I want the first Xaxis date to be the date of the first y value, but it always ends up being a few days before it, I think this is because the plot background is bigger than the data(which I want to keep). How can I get the first QwtScaleDraw label to correspond with my first y value?

    Second, and this is more a general qt/c++ question, is there a better way to get my values in my QwtScaleDraw into human-readable format? Right now I am doing some funky stuff: I take the double value (which is date in unix GMT) then i use ctime to convert it to a char*. Ctime converts my unix GMT to local time, which I don't want (I want it to stay GMT). So I add the seconds that my time is differnt from GMT to the value and then call ctime. There has got to be a better way!


    Qt Code:
    1. class xAxisDates: public QwtScaleDraw
    2. {
    3. public:
    4. xAxisDates()
    5. {
    6. setSpacing(15);
    7. }
    8. virtual QwtText label(double value) const
    9. {
    10. double diff = 7*60*60 //7hrs*60min*60sec - how far my timezone is from GMT
    11.  
    12. time_t valueInGmt = value;
    13. time_t gmtPlusDiffForLocal = value+diff;
    14.  
    15. char * humanTime = ctime(&(gmtPlusDiffForLocal)); //bad form: I add offset to gmt time becuase i use ctime to convert to char*
    16.  
    17. return QString(humanTime);
    18. }
    19. };
    20. /////
    21. setAxisScaleDraw(QwtPlot::xBottom, new xAxisDates);
    22. ////
    To copy to clipboard, switch view to plain text mode 

    this is where I load up the data and where QwtScaleDraw gets its value:
    Qt Code:
    1. void plotFile( double st, double end)
    2. {
    3. newNumbPts = //num of pts in the file
    4. int newNumbPts = endIDX - stIDX;
    5. cout << "newnumb pts: "<< newNumbPts << endl;
    6. t = new double[newNumbPts];
    7. v = new double[newNumbPts];
    8. double *tempT = t;
    9. double *tempV = v;
    10.  
    11. fseek(fp, stIDX*2*sizeof(double), SEEK_SET);
    12. for( int i=0; i<newNumbPts; i++){
    13. int j = fread(tempT, sizeof(double), 1, fp);
    14. int k = fread(tempV, sizeof(double), 1, fp);
    15. tempT++;
    16. tempV++;
    17. }
    18. Curve->setRawSamples(t, v, newNumbPts);
    19.  
    20. };
    To copy to clipboard, switch view to plain text mode 

    Any ideas?
    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,215
    Thanked 849 Times in 798 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtScaleDraw align label to xaxis

    First, when I load the data I want the first Xaxis date to be the date of the first y value, but it always ends up being a few days before it, I think this is because the plot background is bigger than the data(which I want to keep). How can I get the first QwtScaleDraw label to correspond with my first y value?
    Calculating the scale from min/max values is the job of the scale engine. You can use QwtScaleEngine::setAttribute() to modify the algorithm.

    If you don't like any of the results you can also set your scale ( with all its ticks ) manually using QwtPlot::setAxisScaleDiv().

    Uwe

Similar Threads

  1. QTabWidget align
    By AlexD in forum Qt Programming
    Replies: 6
    Last Post: 10th August 2012, 14:19
  2. Replies: 1
    Last Post: 14th October 2010, 19:56
  3. QTextEdit align right.
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 7th November 2009, 21:43
  4. QItemDelegate Align
    By aekilic in forum Qt Programming
    Replies: 43
    Last Post: 1st April 2009, 08:52
  5. Replies: 5
    Last Post: 20th January 2009, 10:13

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.