I have a nice widget that basically looks like a dialog box with a bunch of QSliders on it. The number of sliders varies depending on the situation when the dialog (not an actual QDialog; just a QWidget) is invoked.
Since the varying number of sliders causes the box to be different sizes at different times, I now want to clean things up a bit by confining the sliders to a QScrollArea. If I understand things correctly, such a scroll area would display however many sliders fit within its height, and one could scroll down to see the rest if there were more.
Anyway, I tried a (somewhat complicated) procedure like this:
In constructor of custom QWidget class (m_variableName = member variable):
CustomScrollBox
::CustomScrollBox(QWidget* _parent
){
setWindowTitle(...)
...
m_scrollAreaBox
= new QGroupBox(m_scrollArea
);
m_scrollAreaBox->setLayout(m_layout);
m_scrollArea->setWidget(m_scrollAreaBox);
m_scrollArea->setFixedHeight(250);
m_bottomButton
= new QPushButton(this);
//probably irrelevant ...
[connect calls, etc.]
}
CustomScrollBox::CustomScrollBox(QWidget* _parent){
setWindowTitle(...)
...
m_scrollArea = new QScrollArea(this);
m_scrollAreaBox = new QGroupBox(m_scrollArea);
m_layout = new QGridLayout();
m_scrollAreaBox->setLayout(m_layout);
m_scrollArea->setWidget(m_scrollAreaBox);
m_scrollArea->setFixedHeight(250);
m_bottomButton = new QPushButton(this); //probably irrelevant
...
[connect calls, etc.]
}
To copy to clipboard, switch view to plain text mode
After the constructor, the real, situation-dependent set-up of sliders occurs:
void
CustomScrollBox::SetUpWidgets(){
for([however many sliders the situation calls for]){
CustomSlider* s = new CustomSlider(this, label); //just a QWidget consisting of a QSlider and a QLabel to
//the left of it
...
m_layout->addWidget(s, [grid dimensions as needed]);
}
...
[set text on bottom button, etc., and add it as well]
}
void
CustomScrollBox::SetUpWidgets(){
for([however many sliders the situation calls for]){
CustomSlider* s = new CustomSlider(this, label); //just a QWidget consisting of a QSlider and a QLabel to
//the left of it
...
m_layout->addWidget(s, [grid dimensions as needed]);
}
...
[set text on bottom button, etc., and add it as well]
}
To copy to clipboard, switch view to plain text mode
This process causes nothing to show up on the overall dialog, except for an immobile scroll bar on the left. What, if possible, is the proper order of initialization steps to make this work? My guess is that I might have given something the wrong parent or set a layout at the wrong time, but the rearrganements I've tried so far haven't worked...
Bookmarks