
Originally Posted by
tsp
QSplitter::setSizes is a way to affect to initial sizes of each widget in the
QSplitter. Next is a modified version of your code where the initial sizes are 100, 150 and 200 pixels.
If
QSplitter::setSizes fails then you might want to check what are the original sizes of each widget by using
QSplitter::sizes and if the original sizes are 0 then you are setting sizes too early in the construction phase!
#include <QtGui>
#include <QList>
int main(int argc, char** argv)
{
for (int i = 0; i < 3; ++i) {
splitter->addWidget(te);
if (i % 2 == 0)
te->resize(te->sizeHint().width(), te->fontMetrics().height() * 2);
}
// Set the initial sizes for QSplitter widgets
QList<int> sizes;
sizes << 100 << 150 << 200;
splitter->setSizes(sizes);
mw.setCentralWidget(splitter);
mw.show();
return app.exec();
}
#include <QtGui>
#include <QList>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QSplitter* splitter = new QSplitter(Qt::Vertical);
for (int i = 0; i < 3; ++i) {
QTextEdit* te = new QTextEdit("Text Edit nr. " + QString::number(i));
splitter->addWidget(te);
if (i % 2 == 0)
te->resize(te->sizeHint().width(), te->fontMetrics().height() * 2);
}
// Set the initial sizes for QSplitter widgets
QList<int> sizes;
sizes << 100 << 150 << 200;
splitter->setSizes(sizes);
QMainWindow mw;
mw.setCentralWidget(splitter);
mw.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Needless to say, setSizes was the first thing I tried back then ;-). The stuff didn't work as you can see with this code:
#include <QtGui>
int main(int argc, char** argv)
{
QList<int> sizes;
for (int i = 0; i < 3; ++i) {
splitter->addWidget(te);
sizes << ((i % 2 == 0) ? te->fontMetrics().height() * 2 : te->sizeHint().height());
}
// Set the initial sizes for QSplitter widgets
splitter->setSizes(sizes);
mw.setCentralWidget(splitter);
mw.show();
return app.exec();
}
#include <QtGui>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QList<int> sizes;
QSplitter* splitter = new QSplitter(Qt::Vertical);
for (int i = 0; i < 3; ++i) {
QTextEdit* te = new QTextEdit("Text Edit nr. " + QString::number(i));
splitter->addWidget(te);
sizes << ((i % 2 == 0) ? te->fontMetrics().height() * 2 : te->sizeHint().height());
}
// Set the initial sizes for QSplitter widgets
splitter->setSizes(sizes);
QMainWindow mw;
mw.setCentralWidget(splitter);
mw.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Does anyone have any ideas?
Thanx in advance
P.s. @tsp: The QtGui module includes QtCore which in turns includes QtList. Thus there is no need for that headerfile to be included in the example you provided.
Bookmarks