QSlider inside layout, update on resize.
-
when resizing window Q slider widget keeps its size and is not adjusted to new window size.
I've tried:
setTracking()
adjustSize()
update()
updateGeometry()similar behavior i found in "chip" example project when you resize window or move splitters zoomSlider and RotateSlider will not change their scale. I need click slider or buttons to have it adjusted to new size.
here you can see chip after resize:
both of sliders kept their old sizes.
i think problem is in nesting: slider is in layout -> layout is in widget -> widget in window.
when slider is in window i don't face any problem. -
Hi and welcome to devnet,
What version of Qt are you using ?
What OS are you running ?
Can you provide a minimal compilable example that shows that behaviour ? -
Hi @Lezginohohol
Did you try this ?
https://doc.qt.io/qt-5/qwidget.html#resizeEventvoid QWidget::resizeEvent(QResizeEvent *event)
below is sample code for the QSlider on resizeEvent of widget class.
Widget::Widget(QWidget *parent) : QWidget(parent) , m_Slider(new QSlider(Qt::Horizontal, this)) { } void Widget::resizeEvent(QResizeEvent *event) { qDebug() << event->size() << endl; // Please add the width as per your requirement in place of 20. m_Slider->resize(event->size().width(), 20); }
Output :
All the best, have a great day.
-
@SGaist
Hi.Sorry for late answer. I was offline whole day.
Os - macOS Mojave 10.14.4Qt 5.12.1
XCode 10.2.1
and I checked "chip" example on Windows 10 and planning to check on Ubuntu.
At Windows it is ok. sliders working correctly. -
@Pradeep-P-N said in QSlider inside layout, update on resize.:
Hi. I know this. but my Slider is in layout. with buttons at top and bottom. when slider is single - it is working correctly.
and buttons are not class fields. they created, added to widget, connected where needed.
Now i am working with children() of main widget (where i implemented resize) and trying to locate QSlider object in it. -
Do you mean that the example also has that issue ?
If not, then again, please provide a minimal example that shows it.
-
example "chip"
https://doc.qt.io/qt-5/qtwidgets-graphicsview-chip-example.html
picture i provided in post is this example.
zoomSlider and rotateSlider are defined in class View extending QFrame.
And in debugger they are getting new size, but elements inside slider widget are not resized.
As i said this happens only at macOS. Windows - ok, Ubuntu not checked. -
The chip example works properly here with Qt 5.12.
-
Below is sample code using Layout and Buttons And this works without resizeEvent for the Widget. Let me know if anything is missing.
Widget::Widget(QWidget *parent) : QWidget(parent) , m_Slider(new QSlider(Qt::Horizontal)) , m_Button1(new QPushButton("1")) , m_Button2(new QPushButton("2")) , m_VBLayout(new QVBoxLayout) { m_VBLayout->addWidget(m_Button1); m_VBLayout->addWidget(m_Slider); m_VBLayout->addWidget(m_Button2); this->setLayout(m_VBLayout); }
The Chip example also works fine Qt 5.12.2
-
@Pradeep-P-N
Ok, then i will search problem in my macOS and Qt installation -
@Lezginohohol
Did you try the sample code in macOS ?I did test on Windows, Ubuntu & macOS.
It works fine.