Results 1 to 10 of 10

Thread: QwtSlider cutting axis labels

  1. #1
    Join Date
    Jan 2012
    Location
    Sweden
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: QwtSlider cutting axis labels

    Hi!

    I have a question, in my application I use QwtSlider to indicate some scaled values according to picture below. Slider no. 1 on top has range 0-60000, slider no. 5 at the bottom has range 0-100, and slider no. 2, 3 and 4 also has range 0-100 but these has ScalePosition = NoScale since the scale of slider no. 5 is visually used for these as well.

    The problem is that the axis scale labels are cut off at the widget width as you can see with both the '60000' and the '100' labels. Does anyone have any idea on how to solve this issue?

    QwtSliders.png

    Here is the definition of Slider1 from the .ui file:

    <widget class="QwtSlider" name="Slider1">
    <property name="geometry">
    <rect>
    <x>50</x>
    <y>2</y>
    <width>320</width>
    <height>31</height>
    </rect>
    </property>
    <property name="sizePolicy">
    <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
    <horstretch>0</horstretch>
    <verstretch>0</verstretch>
    </sizepolicy>
    </property>
    <property name="minimumSize">
    <size>
    <width>320</width>
    <height>0</height>
    </size>
    </property>
    <property name="maximumSize">
    <size>
    <width>310</width>
    <height>16777215</height>
    </size>
    </property>
    <property name="upperBound">
    <double>60000.000000000000000</double>
    </property>
    <property name="totalSteps">
    <UInt>60000</UInt>
    </property>
    <property name="pageSteps">
    <UInt>1000</UInt>
    </property>
    <property name="readOnly">
    <bool>true</bool>
    </property>
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="scalePosition">
    <enum>QwtSlider::LeadingScale</enum>
    </property>
    <property name="trough">
    <bool>true</bool>
    </property>
    <property name="groove">
    <bool>false</bool>
    </property>
    <property name="handleSize">
    <size>
    <width>8</width>
    <height>4</height>
    </size>
    </property>
    <property name="borderWidth">
    <number>1</number>
    </property>
    <property name="spacing">
    <number>1</number>
    </property>
    </widget>
    </widget>



    Added after 4 minutes:


    Oh, and I should also mention that I'm using Qwt 6.1.0 compiled with Qt 5.0.2
    Last edited by hahalj; 16th October 2013 at 09:15.

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

    Default Re: QwtSlider cutting axis labels

    If you send a small compilable example ( please no ui code ) I will have a look at it.

    Uwe

  3. #3
    Join Date
    Jan 2012
    Location
    Sweden
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: QwtSlider cutting axis labels

    Hi,

    Thanks for your reply, Uwe.

    I have attached a zipped test project that illustrates the issue. I also have found that it is related to the setHandleSize() function of QwtSlider. I need to set a handle with width=8 and height=4, if I skip this and use default, the QwtSlider widget behaves ok without cutting the upperbound label.

    Tanks again for your support.

    Test project:
    testQwtSlider.zip

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

    Default Re: QwtSlider cutting axis labels

    The reason for this issue is, that the internal layout calculation is supressed while being in Qt::WA_WState_Polished state, but QEvent::PolishRequest is not implemented. Usually there will be a resize event coming later where the layout is calculated ( f.e when resizing the window of your demo ) - so that the issue is not there for most applications.

    In SVN trunk it is fixed ( handling Qt::WA_WState_Polished ). If you need a workaround for Qwt 6.1 you could implement something like this:

    Qt Code:
    1. class YourSlider: public QwtSlider
    2. {
    3. ....
    4. protected:
    5. virtual bool event( QEvent *event )
    6. {
    7. if ( event->type() == QEvent::PolishRequest )
    8. {
    9. const int bw = borderWidth();
    10.  
    11. setBorderWidth( bw + 1 ); // layout calculation triggered
    12. setBorderWidth( bw );
    13. }
    14.  
    15. return QwtSlider::event( event );
    16. }
    17. };
    To copy to clipboard, switch view to plain text mode 

    Uwe

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

    hahalj (21st October 2013)

  6. #5
    Join Date
    Jan 2012
    Location
    Sweden
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: QwtSlider cutting axis labels

    Thanks alot Uwe!
    Will try this workaround, I'll wait for a new official Qwt release before updating.

    Edit: Works perfectly!
    Last edited by hahalj; 21st October 2013 at 14:07.

  7. #6
    Join Date
    Jan 2012
    Location
    Sweden
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: QwtSlider cutting axis labels

    I found another issue also related to using the setHandleSize function:

    When two equally sized sliders have different upper bounds, then the actual size that is displayed are not equal. It is very clear in my attached example. Remove the lines with setHandleSize and they are just equal, otherwise not.

    sliders1.png

    sliders2.png

    testQwtSlider.zip

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

    Default Re: QwtSlider cutting axis labels

    This is normal behavior as the upper scale needs more space to display the 60000.

    Uwe

  9. #8
    Join Date
    Jan 2012
    Location
    Sweden
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: QwtSlider cutting axis labels

    Ok, so there is no way to relate the width to the slider bar excluding the labels?

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

    Default Re: QwtSlider cutting axis labels

    A QLayout will always align complete widgets !

    But you can introduce margins ( QWidget::setContentsMargins() ) - QwtScaleDraw::getBorderDistHint() wiil give you the information you need to calculate them, so that the backbones of the scales are aligned.

    Uwe

  11. #10
    Join Date
    Jan 2012
    Location
    Sweden
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: QwtSlider cutting axis labels

    Ok, will look into that. Thanks!

Similar Threads

  1. Customize tick labels in a QwtSlider
    By RomanRdgz in forum Qwt
    Replies: 16
    Last Post: 10th September 2012, 13:02
  2. How to hide axis labels
    By repepo in forum Qwt
    Replies: 5
    Last Post: 10th November 2011, 08:03
  3. Labels on axis.
    By eugene in forum Qwt
    Replies: 5
    Last Post: 6th August 2010, 13:30
  4. Axis with more labels
    By rakkar in forum Qwt
    Replies: 1
    Last Post: 11th October 2009, 09:26
  5. Relocating axis labels
    By malcom2073 in forum Qwt
    Replies: 0
    Last Post: 9th May 2008, 13:01

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
  •  
Qt is a trademark of The Qt Company.