1 Attachment(s)
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?
Attachment 9700
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
Re: QwtSlider cutting axis labels
If you send a small compilable example ( please no ui code ) I will have a look at it.
Uwe
1 Attachment(s)
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:
Attachment 9701
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:
Code:
{
....
protected:
virtual bool event
( QEvent *event
) {
if ( event
->type
() == QEvent::PolishRequest ) {
const int bw = borderWidth();
setBorderWidth( bw + 1 ); // layout calculation triggered
setBorderWidth( bw );
}
}
};
Uwe
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! :)
3 Attachment(s)
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.
Attachment 9704
Attachment 9705
Attachment 9706
Re: QwtSlider cutting axis labels
This is normal behavior as the upper scale needs more space to display the 60000.
Uwe
Re: QwtSlider cutting axis labels
Ok, so there is no way to relate the width to the slider bar excluding the labels?
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
Re: QwtSlider cutting axis labels
Ok, will look into that. Thanks!