russford
17th March 2010, 19:28
Hi folks,
I'm adding a QTableView into a QVBoxLayout on top of a QPushButton, as follows:
QVBoxLayout* mainLayout = new QVBoxLayout;
QPushButton* btn_OK = new QPushButton(tr("OK"));
connect(btn_OK, SIGNAL(clicked()), this, SLOT(accept()));
model = NULL;
loadModel ();
tableView = new QTableView(this);
tableView->setModel (model);
tableView->verticalHeader()->hide();
tableView->horizontalHeader()->setStretchLastSection (true);
tableView->setSelectionMode (QAbstractItemView::SingleSelection);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows );
mainLayout->addWidget(tableView);
mainLayout->addWidget(btn_OK);
setLayout (mainLayout);
This displays everything, but the dialog's initial size is too narrow and the QTableView uses a horizontal scroll bar. I would like to:
-initially size the dialog so that all the columns are shown without the need to scroll
-prevent the user from resizing the dialog smaller than this size
I have tried setting size policies on the QTableView and the Dialog, turning off the scroll bar, etc. but am not having any luck. Do I need to reimplement sizeHint() for the dialog? Any ideas would be really appreciated.
Russ
I'm adding a QTableView into a QVBoxLayout on top of a QPushButton, as follows:
QVBoxLayout* mainLayout = new QVBoxLayout;
QPushButton* btn_OK = new QPushButton(tr("OK"));
connect(btn_OK, SIGNAL(clicked()), this, SLOT(accept()));
model = NULL;
loadModel ();
tableView = new QTableView(this);
tableView->setModel (model);
tableView->verticalHeader()->hide();
tableView->horizontalHeader()->setStretchLastSection (true);
tableView->setSelectionMode (QAbstractItemView::SingleSelection);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows );
mainLayout->addWidget(tableView);
mainLayout->addWidget(btn_OK);
setLayout (mainLayout);
This displays everything, but the dialog's initial size is too narrow and the QTableView uses a horizontal scroll bar. I would like to:
-initially size the dialog so that all the columns are shown without the need to scroll
-prevent the user from resizing the dialog smaller than this size
I have tried setting size policies on the QTableView and the Dialog, turning off the scroll bar, etc. but am not having any luck. Do I need to reimplement sizeHint() for the dialog? Any ideas would be really appreciated.
Russ