PDA

View Full Version : How to set another QTableView in QDesigner-Layout?



homerun4711
2nd January 2011, 19:05
Hello!

Just another problem... :)

I have an AddressBook-class using a QtDesigner file.
But I can't get the QTableView to work correctly.


class Ui_AddressBook
{
public:
QTableView *tableView;
...

void setupUi(QDialog *AddressBook)
{
...
tableView = new QTableView(AddressBook);
tableView->setObjectName(QString::fromUtf8("tableView"));
tableView->setGeometry(QRect(10, 10, 701, 191));
....
}


AddressBook (inherits above class)

AddressBook::AddressBook(DataManager* dmgr, QWidget *parent): QDialog(parent)
{
setupUi(this); //here the "old" QTableView is set, see above

//customerTableView() belongs to my brandnew DataManager :)
//it returns a QTableView with its model already set
//I would like to display another QTableView here now:
tableView = dmgr->customerTableView();
//result is, that nothing is displayed in the box.

//if I add
tableView.show(); //another small window opens, showing the correct data.
}

What is the correct way to overwrite the "old" model?


delete tableView;

and set a new one?

Kind regards,
HomeR

boudie
2nd January 2011, 20:31
I dont't really get what you're doing ;), but I suggest you try:


tableView = dmgr->customerTableView();
tableView->setParent(this);

homerun4711
2nd January 2011, 22:51
I dont't really get what you're doing

I unterstand what you mean, sometimes I don't get it, too :)

Well, after some good advice I received here in the forum I
build a central class to do all the data management.
It builds and spreads the models, sets the QTableViews and is responsible for
Data I/O.

AddressBook-Class:

DataManager* dmgr //manages data stuff
Q_CHECK_PTR(dmgr);
...
dmgr->customerTableView();//returns a QTableView*

datamanager.h


private:
QTableView *m_customerTableView;
public:
QTableView *customerTableView();

datamanager.cpp


...
m_customerTableView = new QTableView;
m_customerTableView->setModel(model_customer);
...
QTableView *DataManager::customerTableView()
{
Q_ASSERT(m_customerTableView);
return m_customerTableView; //returns QTableView with model set
}

The model is accessible and not empty, I just can not get it to display in
the box.

Your suggestion, adding tableView->setParent(this) inserts a new widget into my window. See here: 5676

Without setParent, but with tableView->show() the data is displayed in a new popup window.

How can I assign the prepared QTableView correctly to the one provided by the layout?

Kind regards,
HomeR

homerun4711
3rd January 2011, 08:54
Everything is working fine if I just set the model to the
one available from DataManager* dmgr .


tableView->setModel(dmgr->customerModel());

but then I have to set all tableView-related things



m_customerTableView->setObjectName("CustomerTableView");;
m_customerTableView->setSortingEnabled(true);
m_customerTableView->sortByColumn(0, Qt::DescendingOrder);
m_customerTableView->setSelectionMode(QAbstractItemView::SingleSelectio n);
m_customerTableView->setSelectionBehavior(QAbstractItemView::SelectRows );
selectionModelCustomer = new QItemSelectionModel(model_customer);
m_customerTableView->setSelectionModel(selectionModelCustomer);
headerViewCustomer = m_customerTableView->horizontalHeader();

for each component instead of having them just in one spot.

But I guess this is possible somehow since I found out that if I assign the tableView from DataManager* dmgr it is possible to display its name (which is set in dmgr) correctly.


Q_CHECK_PTR(dmgr->customerTableView());
tableView = dmgr->customerTableView();
out << "tableViewName: " << tableView->objectName() << "\n";


So it is available, I just can not get it to display inside the correct spot.

Has someone an idea how this could be accomplished?

Kind regards,
HomeR