QDial pointer start position(value - 0) at top
-
Hi
Did you try with
If that is not working with Dial then you have to do it manually.
-
@sayan275
Hi
Ok you must have something that block images then.
Anyway, it show the property
"inverted appearance "
that normally flips a slider to be reversed.
But sadly it didn't work with 0-360 as the zero is still in the bottom. -
@mrjj sorry I got your posted image..its the property.
Yes it didn't work...I tried all possible combinations with the flags available.
Can we rotated a widget? .. can't remember any api.
Meanwhile I got the expected output by calculating with +/- 180// if(value > 180) // value -= 180; // else if(value <= 180) // value += 180;
I didn't want to update the value in this manner.
@mrjj Anyways thanks for your reply.
-
@sayan275
well we cant rotate a widget as such
but we could subclass it and then flip the painter.
If that works in terms of navigation, im not sure.void QDial::paintEvent(QPaintEvent *) { QStylePainter p(this); QStyleOptionSlider option; initStyleOption(&option); p.drawComplexControl(QStyle::CC_Dial, option); }
use p and
https://doc.qt.io/qt-5/qtwidgets-painting-transformations-example.html
to flip it and see :) -
Hi
Just as a note.void MyDial::paintEvent(QPaintEvent *event) { QStylePainter p(this); QStyleOptionSlider option; initStyleOption(&option); p.translate(0, height()); p.scale(1.0, -1.0); p.drawComplexControl(QStyle::CC_Dial, option); }
Did draw as we wanted and using keys (left , right ) moves it ok
but click and drag with the mouse it jumps back to the old zero.So sadly was not a solution as navigation did went banans.
-
@Pablo-J-Rogina yes...we need to wrap...so that the starting and endpoints are similar.
-
@sayan275
here ya go://.h #ifndef JHDIAL_H #define JHDIAL_H #include <QDial> class JhDial : public QDial { Q_OBJECT Q_PROPERTY(int adjustedValue READ adjustedValue WRITE setAdjustedValue NOTIFY adjustedValueChanged) public: explicit JhDial(QWidget *parent = nullptr); inline int adjustedValue() const { return m_adjustedValue; } signals: void adjustedValueChanged(int adjustedValue); public slots: void setAdjustedValue(int adjustedValue); private: int mapValueToRange(int y, int y_min, int y_max, int x_min, int x_max); void adjustValue(int value); int m_adjustedValue = -1; }; #endif // JHDIAL_H
//.cpp #include "jhdial.h" JhDial::JhDial(QWidget *parent) : QDial(parent) { connect(this, &QDial::valueChanged, this, &JhDial::adjustValue); setWrapping(true); setRange(0,360); setAdjustedValue(0); } void JhDial::setAdjustedValue(int adjustedValue) { if (m_adjustedValue == adjustedValue) return; if(adjustedValue < 180) setValue(mapValueToRange(adjustedValue,0,179,180,360)); else setValue(mapValueToRange(adjustedValue,180,360, 0, 180)); } int JhDial::mapValueToRange(int y, int y_min, int y_max, int x_min, int x_max) { return qRound((y-y_min)/static_cast<double>(y_max-y_min)*(x_max-x_min)+x_min); } void JhDial::adjustValue(int value) { if(value < 180) m_adjustedValue = mapValueToRange(value,0, 179, 180, 360); else m_adjustedValue = mapValueToRange(value,180, 360, 0, 180); emit adjustedValueChanged(m_adjustedValue); }
You may have to adjust the borders for the mapping, so that they don't overlap, I mad this in a rush ;)
you had to, cleaned it up a bit.