I think it is the same problem as : QScrollArea resizing QWidget
but there are not solution. so let me expose the problem.
- test 2 inherited from QWidget:
- composed :
- vector of QSpinBox
- QScrollArea
- QVBoxLayout
- test2 (QWidget) <- QScrollArea <- QVBoxLayout <- Spinbox
- Problems :
- There are no scrollbar
- [FIXED] The inside of the scrollbar is shrinked to fit so little space nothing can be read (the window can be resized during execution that will cause the inside to get bigger and be readable nevertheless no scrollbar will appear)
I Think problems come from a single source :: Size Hints and Layouts (http://qt-project.org/doc/qt-5.1/qtwidgets/qscrollarea.html#details)
The second problem (shrinked widget) can be solved by setting "c->setSizeConstraint(QLayout::SetMinimumSize);"
I am currently seeking a solution for the missing scrollbar
here is a code showing my problem :
<c++>
#include <QWidget>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QSpinBox>
class test2 : public QWidget
{
Q_OBJECT
public:
test2(QWidget *parent = 0) :QWidget(parent)
{
b = new QScrollArea(this);
c = new QVBoxLayout;
for (int i = 0; i < 10; i++)
{
a.push_back(new QSpinBox());
c->addWidget(a[i]);
}
c->setSizeConstraint(QLayout::SetMinimumSize);
b->setLayout(c);
b->resize(200, 200);
}
~test2()
{
for (int i = 0; i < 10; i++)
delete a[i];
}
protected:
QVector<QSpinBox*> a;
QScrollArea* b;
QVBoxLayout* c;
};
int main(int argc, char *argv[])
{
///*
QApplication app(argc, argv);
test2 a;
a.show();
return app.exec();//*/
}
EDIT :: found a Solution here:
http://qt-project.org/forums/viewthread/295
if you don't want to read huge amount of useless code here what he has done ::
he warped the layout inside a widget
Solution :: inherit the Object from ScrollBar <- Widget <- Layout
instead of widget <- ScrollBar <- Layout
but it a work around not really a solution...
I going to try on the example I gave.
it works. Does anyone have a better solution ??
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…