Hello, I have five days of experience with Qt.
I've completed my program for the most part, but there's something I just can't get to work.
I want to place QTableView (which has 6 columns) to the middle of the window.
I've tried layouts but that's apparently not what I want.
I've also tried QTableView's move method but that doesn't work, either.
Here's my latest try:
model = new customTable(999, 6, this);
model
->setHorizontalHeaderItem
(0,
new QStandardItem(tr
("Manufacturer")));
model
->setHorizontalHeaderItem
(1,
new QStandardItem(tr
("Model")));
model
->setHorizontalHeaderItem
(2,
new QStandardItem(tr
("Type")));
model
->setHorizontalHeaderItem
(3,
new QStandardItem(tr
("Available")));
model
->setHorizontalHeaderItem
(4,
new QStandardItem(tr
("Misc")));
model
->setHorizontalHeaderItem
(5,
new QStandardItem(tr
("Cost")));
model->table->setModel(model);
model
->table
->horizontalHeader
()->setResizeMode
(QHeaderView::ResizeToContents);
model->table->adjustSize();
model
->table
->move
(QApplication::desktop()->screen
()->rect
().
center() - model
->table
->rect
().
center());
setCentralWidget(model->table);
model = new customTable(999, 6, this);
model->setHorizontalHeaderItem(0, new QStandardItem(tr("Manufacturer")));
model->setHorizontalHeaderItem(1, new QStandardItem(tr("Model")));
model->setHorizontalHeaderItem(2, new QStandardItem(tr("Type")));
model->setHorizontalHeaderItem(3, new QStandardItem(tr("Available")));
model->setHorizontalHeaderItem(4, new QStandardItem(tr("Misc")));
model->setHorizontalHeaderItem(5, new QStandardItem(tr("Cost")));
model->table->setModel(model);
model->table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
model->table->adjustSize();
model->table->move(QApplication::desktop()->screen()->rect().center() - model->table->rect().center());
setCentralWidget(model->table);
To copy to clipboard, switch view to plain text mode
Doesn't work... the table just isn't moved. (customTable is a class I made for my own needs - like custom SLOTs and SIGNALs. etc; it inherits from QStandardItemModel and has a public QTableView *table.)
What do I have in mind?
Well, I want my table to be in the middle (ala Wordpad), with a blue background.
I've tried skimming through a lot of classes and methods, but nothing I've tried so far worked. (I also tried QHBoxLayout, but that's obviously not something I want?)
Thank you in advance... and sorry if the solution is easy, I'm just not experienced enough with Qt.
(I'm using Qt 4.8; C++.)
Bookmarks