Multiple identical QSliders do not resize properly on window resize
-
Re: [QSlider inside layout](update on resize.)
When I have multiple, identical QSliders, with the same settings and the same value, the sliders do not resize properly when the main window is resized. When the value of at least one slider is different from the others the resizing works as expected. I'm using Qt 5.13.0 on macOS 10.14.6.
When running the example code below and resizing the window, this is the result which is not expected:
When the value of one of the sliders is changed to be different from the other, and the window is resized again, this is the result which looks as expected:
Minimal example that shows the effect
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { auto w = new QWidget; auto layout = new QGridLayout(w); setCentralWidget(w); auto slider1 = new QSlider; slider1->setMinimum(0); slider1->setMaximum(20); slider1->setOrientation(Qt::Horizontal); slider1->setTickInterval(5); slider1->setTickPosition(QSlider::TicksBelow); layout->addWidget(slider1, 0, 0); auto slider2 = new QSlider; slider2->setMinimum(0); slider2->setMaximum(20); slider2->setOrientation(Qt::Horizontal); slider2->setTickInterval(5); slider2->setTickPosition(QSlider::TicksBelow); layout->addWidget(slider2, 1, 0); }
-
I doubt that the slider value influences the size policies of your widgets.
Try to set a parent (your mainWindow) to your sliders. It may fix it
auto slider1 = new QSlider(this); // Same with slider2
Edit:
Maybe some invisible layout items (plaaceholders from your Grid) are blocking the expansion of your sliders, in fact you are using a GridLayout.
What does it look like, when you use QHBoxLayout / QVBoxLayout? -
The line where you add
slider2
to your Layout is missing (I guess a typo).
But nevertheless, I added the missing line and it works for me on Windows.So maybe it`s a macOS problem (Qt code doesnt look wrong).
-
Hi
This reminds me a bit of the posters having issues on MacOs with refresh
of widgets.
https://bugreports.qt.io/browse/QTBUG-68740
However, here in this post, it seems layout related so not sure its the same reason. -
@pl45m4 said in Multiple identical QSliders do not resize properly on window resize:
I doubt that the slider value influences the size policies of your widgets.
I don't know what it does, but if the sliders have different values they behave okay, if the values (and other settings) are identical they do not.
Try to set a parent (your mainWindow) to your sliders. It may fix it
This did not help.
Maybe some invisible layout items (plaaceholders from your Grid) are blocking the expansion of your sliders, in fact you are using a GridLayout.
What does it look like, when you use QHBoxLayout / QVBoxLayout?It behaves exactly the same with a QVBoxLayout. There are no other items, the code I posted above is all there's needed to obtain this behaviour.
-
Isn`t this post the same as this one here (https://forum.qt.io/topic/105679/multiple-identical-qsliders-do-not-resize-properly-on-window-resize)?
I copied the code into an empty project to test it and it worked for me like it should.
Do you have any slots connected to your value-changed signal? -
@pl45m4 said in Multiple identical QSliders do not resize properly on window resize:
Isn`t this post the same as this one here (https://forum.qt.io/topic/105679/multiple-identical-qsliders-do-not-resize-properly-on-window-resize)?
Wow, it looks like a spambot just copied my post. That's not my account but it is my post (but partially).
I copied the code into an empty project to test it and it worked for me like it should.
Do you have any slots connected to your value-changed signal?This code is all there is. No slots connected (if I do connect slots however, the problem persists). Could it be a mac specific issue? I encountered this issue first in a larger project with all kinds of other stuff in it. I created this small example to see if it was a Qt issue or something in my code. The small example showed the exact same problem so it does seem to be a Qt thing (at least on macOS).
-
Check out the answers
below the "spambots" post:)
[Edit: Posts were moved into this thread. ~kshegunov]@mrjj posted a bugreport link there, where your problem may refer to.
Please report the author of the other post.
Never seen a bot stealing / cloning random posts. Normally they try to sell something or post suspicious links :) -
@mrjj said in Multiple identical QSliders do not resize properly on window resize:
Hi
This reminds me a bit of the posters having issues on MacOs with refresh
of widgets.
https://bugreports.qt.io/browse/QTBUG-68740
However, here in this post, it seems layout related so not sure its the same reason.That issue does seem to be fixed, though. Plus, I've only seen this issue with sliders and not with other widgets.
I decided to create a new bug report for this: https://bugreports.qt.io/projects/QTBUG/issues/QTBUG-77368