Results 1 to 7 of 7

Thread: Qwt : align center the date/time label text on an bottom axis

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2018
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Qwt : align center the date/time label text on an bottom axis

    With Qwt, I want that the time and the date are both center under the stick under a bottom axis, but the time is still on the left side like in this picture :

    Capture.jpg

    I have tried to use

    Qt Code:
    1. QwtDateScaleDraw::setLabelAlignment(Qt::AlignHCenter|Qt::AlignBottom);
    To copy to clipboard, switch view to plain text mode 

    But the time is still on the left.

    I have tried to subclass the QwtScaleDraw like this:

    Qt Code:
    1. class MyDateScaleDraw:public QwtDateScaleDraw
    2. {
    3. public:
    4. QwtText label(double value) const override
    5. {
    6. QwtText txt=QwtDateScaleDraw::label(value);
    7. txt.setRenderFlags(Qt::AlignHCenter);
    8. return txt;
    9. }
    10. };
    To copy to clipboard, switch view to plain text mode 

    But the time is still on the left side.

    Somebody know how to center the time ?

  2. #2
    Join Date
    Jul 2018
    Posts
    3
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Qwt : align center the date/time label text on an bottom axis

    Actually I didn't get which way you are following:
    If it is Layout design
    http://doc.qt.io/qt-5/qtwidgets-layo...s-example.html

    take QGridlayout and add your label at pirtuculer position
    or
    my_label ->setGeometry(x,y,width,hight);

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qwt : align center the date/time label text on an bottom axis

    Qt Code:
    1. class YourScaleDraw: public QwtScaleDraw
    2. {
    3. virtual QwtText label( double value ) const override
    4. {
    5. auto text = QwtScaleDraw::label( value );
    6. text.setRenderFlags( ... );
    7. return text;
    8. }
    9. };
    10.  
    11. plot->setAxisScaleDraw( ..., new YourScaleDraw() );
    To copy to clipboard, switch view to plain text mode 
    The render flags go as flags into https://doc.qt.io/qt-5/qpainter.html#drawText-4.
    If you like to do more fancy texts you can consider using rich text labels.

    In your case you have to derive from QwtDateScaleDraw - the idea is the same.

    Uwe
    Last edited by Uwe; 19th July 2018 at 09:31.

  4. #4
    Join Date
    Jul 2018
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qwt : align center the date/time label text on an bottom axis

    Thanks Uwe for your answer,

    Your suggestion is what I have tried (see the code in my post), but the
    Qt Code:
    1. setRenderFlags
    To copy to clipboard, switch view to plain text mode 
    in MyDateScaleDraw class doesn't change the alignment of the axis label...
    Last edited by vcloarec; 19th July 2018 at 14:35.

Similar Threads

  1. Date-time axis
    By Cat in forum Qwt
    Replies: 1
    Last Post: 20th October 2016, 04:46
  2. Align WindowTitle text to the Center in Windows 10
    By santosh.kumar in forum Qt Programming
    Replies: 3
    Last Post: 6th November 2015, 15:53
  3. Align text and icon of QToolButton on center
    By bibhukalyana in forum Qt Programming
    Replies: 7
    Last Post: 24th November 2014, 12:46
  4. KDChart Date-time Axis howto?
    By galrub in forum Qt Programming
    Replies: 0
    Last Post: 15th October 2012, 11:36
  5. Time/Date Axis
    By sigger in forum Qwt
    Replies: 12
    Last Post: 1st May 2011, 09:55

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.