0

I am adding several push buttons in QVBoxLayout and adding this layout in QDockWidget, now I want to add some scroll bar in the same Layout(DockWidget) to change(Increase/Decrease) data shown in separate EditBox.

The problem is the Scroll bar is added above the buttons,I want all the buttons at right side and the scroll bar in the left side.

The reason why I am using QDockWidget is I am also adding animation effect using QPropertyAnimation class.

Below is the sample code

QDockWidget dock(QLatin1String("Last filters"));
QWidget* multiWidget = new QWidget();
QVBoxLayout* layout = new QVBoxLayout();
QPushButton* filter1 = new QPushButton(QLatin1String("Filter number 1"));
QPushButton* filter2 = new QPushButton(QLatin1String("Filter number 2"));
QPushButton* filter3 = new QPushButton(QLatin1String("Filter number 3"));
QPushButton* filter4 = new QPushButton(QLatin1String("Filter number 4"));
QPushButton* filter5 = new QPushButton(QLatin1String("Filter number 5"));
QLabel* label = new QLabel(QLatin1String("QPushButtons"));

layout->addWidget(filter1);
layout->addWidget(filter2);
layout->addWidget(filter3);
layout->addWidget(filter4);
layout->addWidget(filter5);
layout->addWidget(label);
multiWidget->setLayout(layout);
dock.setWidget(multiWidget);

** For animation

QPropertyAnimation *animation = new QPropertyAnimation(dockMenu, "geometry");
animation->setDuration(250);    
QRect startRect(-100,20,100,80);        
QRect endRect(20,20,100,80);                            
dockMenu->show();
animation->setStartValue(startRect);
animation->setEndValue(endRect);    
animation->start();

For this application this answer at Multiple widgets on a QDockWidget helped me but now to add the scrollbar I am not able to relocate/move the widgets

ScreenShot

1 Answers1

0

Your code sample does not reflect the attached screenshot so I'm not 100% sure if this is what you're looking, but...

If you swap the QVBoxLayout for a QGridLayout, you can place the scrollbar in the first column and set it to expand over the max number of rows. The buttons can be placed in the second column.

QGridLayout documentation: https://doc.qt.io/archives/qt-4.8/qgridlayout.html#details

And some basic layout examples from Qt which may give you some ideas: https://doc.qt.io/qt-5/qtwidgets-layouts-basiclayouts-example.html

parcmeters
  • 41
  • 3