Re: Resizing QSqlTableModel
For starters, you won't resize the model but rather the table widget you're using to display it (see http://doc.trolltech.com/4.1/qt4-interview.html). This could either be a QTableView or QTableWidget. Get the horizontal header of the table usingAnd resize the section you want using
Code:
void QHeaderView::resizeSection(int logicalindex,
int size
);
Re: Resizing QSqlTableModel
Thanks, but I don't realy know how to use it.
I'm creating my QTableView in function Okno::baza() :
Code:
db.setDatabaseName("magazyn");
db.open();
tabelka->setTable("produkty");
tabelka->select();
tabelka->setHeaderData(0, Qt::Horizontal, tr("Id"));
tabelka->setHeaderData(1, Qt::Horizontal, tr("Nazwa"));
tabelka->setHeaderData(2, Qt::Horizontal, tr("Ilość"));
tabelka->setHeaderData(3, Qt::Horizontal, tr("Cena Netto"));
tabelka->setHeaderData(4, Qt::Horizontal, tr("Data Ważności"));
view->setModel(tabelka);
In constructor Okno::Okno() I'm adding view do layout:
Code:
baza();
glowny->addWidget(view, 0, Qt::AlignHCenter);
centralWidget->setLayout(glowny);
setCentralWidget(centralWidget);
Class Okno inherits from QMainWindow.
Re: Resizing QSqlTableModel
Quote:
Originally Posted by Corran
This could either be a QTableView or QTableWidget.
It can't be QTableWidget. Its setModel() method is private. It can probably be QTreeView, though.
Re: Resizing QSqlTableModel
Sorry for refreshing this topic, but I haven't found sloution for my problem yet.
So I'm asking again: Is there any way to resize colums in QTableView ?
Re: Resizing QSqlTableModel
I think the question has already been answered in the second post of this thread.
Re: Resizing QSqlTableModel
Quote:
Originally Posted by teS
Sorry for refreshing this topic, but I haven't found sloution for my problem yet.
So I'm asking again: Is there any way to resize colums in QTableView ?
Code:
viewModel->setHeaderData(0, Qt::Horizontal, "ID");
viewModel->setHeaderData(1, Qt::Horizontal, "SSN");
viewModel->setHeaderData(2, Qt::Horizontal, "WholeName");
viewModel->setHeaderData(3, Qt::Horizontal, "SSSN");
viewModel->setHeaderData(4, Qt::Horizontal, "SName");
viewModel->setHeaderData(5, Qt::Horizontal, "City");
viewModel->setHeaderData(6, Qt::Horizontal, "Address");
viewModel->setQuery(queryStr);
if (viewModel
->lastError
().
type() == QSqlError::NoError){ wnui.wholeNameView->setModel(viewModel);
if (viewModel->rowCount() > 0){
for (int i = 0; i < viewModel->rowCount(); ++i)
this->wnui.wholeNameView->verticalHeader()->resizeSection(i,20);
for (int i = 0; i < 7; ++i)
wnui.wholeNameView->resizeColumnToContents(i);
}
}
}
where wholeNameView is the name of the QTableView object in my wholenamedlg.ui file. "wnui" was the name assigned to the Ui class in the wholenamedlg class definition in the wholenamedlg.h file, and wholeNameDlgUI is the ObjectName of the wholenamedlg.ui form itself.
Code:
private:
Ui::wholeNameDlgUI wnui;