PDA

View Full Version : Model, view, resize to show all data



jcr
17th April 2006, 19:53
Hello,
The constructor is like this:


Test::Test(QWidget* parent)
: QWidget(parent)
{
//Model
QDirModel* model = new QDirModel;
QModelIndex parentIndex = model->index(QDir::currentPath());
//text
text = new QTextEdit;
int row = model->rowCount(parentIndex);
int col = model->columnCount(parentIndex);
for(int i(0); i<row; ++i)
for(int j(0); j<col; ++j)
{
QModelIndex index = model->index(i, j, parentIndex);
text->append(model->data(index, Qt::DisplayRole).toString());
}
//view
view = new QTableView;
view->setModel(model);
view->setRootIndex(parentIndex);
//splitter
splitter = new QSplitter(this);
splitter->addWidget(text);
splitter->addWidget(view);
}

How can I make sure that the text, view, and splitter will resize automatically to display all the data?
Many thanks in advance.

jacek
17th April 2006, 20:09
Set a layout for that Test widget or subclass the QSplitter instead of QWidget.

jcr
17th April 2006, 20:59
Jacek,
Thanks; things are starting to look good:



Test::Test(QWidget* parent)
: QWidget(parent)
{
QHBoxLayout* mainLayout = new QHBoxLayout(this);
//Model
QDirModel* model = new QDirModel;
QModelIndex parentIndex = model->index(QDir::currentPath());
//text
QTextEdit* text;
text = new QTextEdit;
int row = model->rowCount(parentIndex);
int col = model->columnCount(parentIndex);
for(int i(0); i<row; ++i)
for(int j(0); j<col; ++j)
{
QModelIndex index = model->index(i, j, parentIndex);
text->append(model->data(index, Qt::DisplayRole).toString());
}
//view
QAbstractItemView* view = new QTableView;
view->setModel(model);
view->setRootIndex(parentIndex);
//splitter
QSplitter* splitter = new QSplitter;
mainLayout->addWidget(splitter);
splitter->addWidget(text);
splitter->addWidget(view);
QList<int> list;
list << 1000 << 1000;
splitter->setSizes(list);
}

But the "text" and "view" boxes of the splitter are of the same size. I would like their sizes to adjust automatically to the amount of data that needs to be displayed so that scroll bars would not be needed. I tried to play with the setSizes function but without luck.