I have a few questions about frames.
Here is a test program I have been experimenting with
class BuildGui : public QMainApplication
{
public:
private:
};
BuildGui
::BuildGui(QWidget* parent
= 0) : QMainApplication
(parent
){
layout->addWidget(w1);
layout->addWidget(w2);
cw->setLayout(layout);
sa->setWidget(cw);
setCentralWidget(sa);
}
{
return le;
}
class BuildGui : public QMainApplication
{
public:
BuildGui(QWidget* parent = 0);
private:
QWidget* makeWidget(QString text);
QVBoxLayout* layout;
};
BuildGui::BuildGui(QWidget* parent = 0) : QMainApplication(parent)
{
QWidget* w1 = makeWidget("Ex 1");
QWidget* w2 = makeWidget("Ex 2");
layout = new QVBoxLayout;
layout->addWidget(w1);
layout->addWidget(w2);
QWidget* cw = new QWidget;
cw->setLayout(layout);
QScrollArea* sa = new QScrollArea;
sa->setWidget(cw);
setCentralWidget(sa);
}
QWidget* BuildGui::makeWidget(QString text)
{
QLineEdit* le = new QLineEdit(text);
return le;
}
To copy to clipboard, switch view to plain text mode
which works as expected - I see the 2 text boxes one above the other with "Ex 1" and "Ex 2" for the text.
Now I add this method:
{
f
->setFrameStyle
(QFrame::Box);
w->setParent(f);
return f;
}
QWidget* BuildGui::addFrame(QWidget w)
{
QFrame* f = new QFrame;
f->setFrameStyle(QFrame::Box);
w->setParent(f);
return f;
}
To copy to clipboard, switch view to plain text mode
and modify the constructor:
...
// layout->setWidget(w1);
layout->setWidget(f1);
QWidget* f1 = addFrame(sc1);
...
// layout->setWidget(w1);
layout->setWidget(f1);
To copy to clipboard, switch view to plain text mode
now the "Ex 1" box does not show up. If I add
f1->setMinimumSize(50,50);
f1->setMinimumSize(50,50);
To copy to clipboard, switch view to plain text mode
then it is visible.
So my question is
Can i make the frame automatically adjust to the size of the widget it is framing?
Thanks,
Steve
PS I know some widgets have a setFrame() method but I want this to work for framinh any widget.
Bookmarks