QSlider does not reach max or min
-
Hi guys,
I create a new window by hand, because I use the QColorWheel, which is not compatible with the QT Creator Designer. ( I use QT 5.10)
The window is created and I can use it. Only problem is, if I move the slider by hand, I can't reach the set maximum and minimum values (0 and 255). The changes are made visible in the QLine underneath. I also can change the value of the slider by this line. There it is possible to set the min/ max values, which are then accepted and realized on the slider.What do I need to reach the end of the slider/ min/max values by moving my mouse.
thanks in advance,
Fabianp.s.: here is the code for creating the slider
/*reset the color to black*/ activeColor.setAlpha(0); activeColor.setRed(0); activeColor.setGreen(0); activeColor.setBlue(0); /*set up the main window */ QScreen *ratio = QGuiApplication::primaryScreen(); window->setGeometry(ratio->geometry().width()-250,0,250,250); window->setFixedSize(250,250); window->setObjectName("ColorPicker"); /* Graphical Objects */ QWidget *windowCentral = new QWidget(window); QGridLayout *windowLayout = new QGridLayout(windowCentral); windowColorWheel = new ColorWheel(window); windowWhiteSlider = new QSlider(window); windowWhiteSlider->setRange(0,255); windowWhiteSlider->setOrientation(Qt::Horizontal); windowWhiteSlider->setTickInterval(1); windowWhiteSlider->setSingleStep(1); windowWhiteSlider->setPageStep(10); windowLine = new QLineEdit(window); windowLine->setMaximumWidth(100); windowLayout->setObjectName("centralLayout"); windowLayout->addWidget(windowColorWheel); windowLayout->addWidget(windowWhiteSlider); windowLayout->addWidget(windowLine); windowCentral->setLayout(windowLayout); window->setCentralWidget(windowCentral); /* Actions */ windowActionQuit = new QAction(window); windowActionQuit->setShortcut(QKeySequence("Ctrl+Q")); windowActionClose = new QAction(window); windowActionClose->setShortcut(QKeySequence("Ctrl+W")); window->addAction(windowActionQuit); window->addAction(windowActionClose); /* window connections */ connect(windowActionClose,SIGNAL(triggered()),window,SLOT(close()),Qt::DirectConnection); //close by Ctrl+W //colorwheel or slider changed, update the textline connect(windowColorWheel,SIGNAL(colorChanged(QColor)),window,SLOT(setLine(void)),Qt::DirectConnection); //if color wheel is changed, change text line connect(windowWhiteSlider,SIGNAL(sliderMoved(int)),window,SLOT(setLine(void)),Qt::DirectConnection); //the textline was changed, update colorwheel and slider connect(windowLine,SIGNAL(editingFinished()),window,SLOT(setColor()),Qt::DirectConnection); connect(windowLine,SIGNAL(returnPressed()),window,SLOT(setColor()),Qt::DirectConnection);
-
Hi guys,
I create a new window by hand, because I use the QColorWheel, which is not compatible with the QT Creator Designer. ( I use QT 5.10)
The window is created and I can use it. Only problem is, if I move the slider by hand, I can't reach the set maximum and minimum values (0 and 255). The changes are made visible in the QLine underneath. I also can change the value of the slider by this line. There it is possible to set the min/ max values, which are then accepted and realized on the slider.What do I need to reach the end of the slider/ min/max values by moving my mouse.
thanks in advance,
Fabianp.s.: here is the code for creating the slider
/*reset the color to black*/ activeColor.setAlpha(0); activeColor.setRed(0); activeColor.setGreen(0); activeColor.setBlue(0); /*set up the main window */ QScreen *ratio = QGuiApplication::primaryScreen(); window->setGeometry(ratio->geometry().width()-250,0,250,250); window->setFixedSize(250,250); window->setObjectName("ColorPicker"); /* Graphical Objects */ QWidget *windowCentral = new QWidget(window); QGridLayout *windowLayout = new QGridLayout(windowCentral); windowColorWheel = new ColorWheel(window); windowWhiteSlider = new QSlider(window); windowWhiteSlider->setRange(0,255); windowWhiteSlider->setOrientation(Qt::Horizontal); windowWhiteSlider->setTickInterval(1); windowWhiteSlider->setSingleStep(1); windowWhiteSlider->setPageStep(10); windowLine = new QLineEdit(window); windowLine->setMaximumWidth(100); windowLayout->setObjectName("centralLayout"); windowLayout->addWidget(windowColorWheel); windowLayout->addWidget(windowWhiteSlider); windowLayout->addWidget(windowLine); windowCentral->setLayout(windowLayout); window->setCentralWidget(windowCentral); /* Actions */ windowActionQuit = new QAction(window); windowActionQuit->setShortcut(QKeySequence("Ctrl+Q")); windowActionClose = new QAction(window); windowActionClose->setShortcut(QKeySequence("Ctrl+W")); window->addAction(windowActionQuit); window->addAction(windowActionClose); /* window connections */ connect(windowActionClose,SIGNAL(triggered()),window,SLOT(close()),Qt::DirectConnection); //close by Ctrl+W //colorwheel or slider changed, update the textline connect(windowColorWheel,SIGNAL(colorChanged(QColor)),window,SLOT(setLine(void)),Qt::DirectConnection); //if color wheel is changed, change text line connect(windowWhiteSlider,SIGNAL(sliderMoved(int)),window,SLOT(setLine(void)),Qt::DirectConnection); //the textline was changed, update colorwheel and slider connect(windowLine,SIGNAL(editingFinished()),window,SLOT(setColor()),Qt::DirectConnection); connect(windowLine,SIGNAL(returnPressed()),window,SLOT(setColor()),Qt::DirectConnection);
@Fabian727 Hi, friend. Welcome.
can you
qDebug
QSlider
value in slot function ofsetLine
, and why did you usevoid
notint
in slot function?connect(windowWhiteSlider,SIGNAL(sliderMoved(int)),window,SLOT(setLine(void)),Qt::DirectConnection);
void
->int
, andqDebug
value in slot function.connect(windowWhiteSlider,SIGNAL(sliderMoved(int)),window,SLOT(setLine(int)),Qt::DirectConnection);
-
I'm unable to duplicate your issue. I put this code together to test based on your creation of
windowWhiteSlider
and everything works fine. I can get to 0 and to 255 with the mouse.#include <QApplication> #include <QSlider> #include <QHBoxLayout> #include <QLabel> #include <QDebug> int main(int ac, char **av) { QApplication app(ac, av); auto window = new QWidget(); window->resize(300,150); auto windowWhiteSlider = new QSlider(window); windowWhiteSlider->setRange(0,255); windowWhiteSlider->setOrientation(Qt::Horizontal); windowWhiteSlider->setTickInterval(1); windowWhiteSlider->setSingleStep(1); windowWhiteSlider->setPageStep(10); windowWhiteSlider->setValue(0); auto label = new QLabel(window); label->setText(QString::number(windowWhiteSlider->value())); QObject::connect(windowWhiteSlider, &QSlider::valueChanged, label, [=](int v) { label->setText(QString::number(v)); }); auto layout = new QHBoxLayout(); layout->addWidget(windowWhiteSlider); layout->addWidget(label); window->setLayout(layout); window->show(); return app.exec(); }
Can you give us a video or a screenshot or more information on what the problem is? I was unable to duplicate it with what you shared.
-
Hello,
today i wanted to introduce a Slider which works from INT32_MAX to INT32_MIN.
But this is not possible.Initial State with Limits => INT32_MAX, INT32_MIN
When Clicking and Sliding
After Release
I found out that the Limit for a good Version Working is at INT32_MAX/2, INT32_MIN/2
Initial
Lower Limit
Upper Limit
So my Question, is this a Bug or a Feature?
I used Qt 5.15.2 with c++14.
Thanks and Bye
-
Since sliderPosition is only a signed int, the max range can also be max 2^31-1.
A slider with such a huge range is useless since a user can never do a valid input then. Scale your slider values. -
Ah OK, so internal Range is also signed int32 and not unsigned int32.
The Scale Idea is a good workaround and you are right.
But for quick random value setting i thought it would be easy just to use the value and define the maximum Limits.@Magge2k said in QSlider does not reach max or min:
Ah OK, so internal Range is also signed int32 and not unsigned int32.