Results 1 to 4 of 4

Thread: How to set another QTableView in QDesigner-Layout?

  1. #1
    Join Date
    Oct 2010
    Posts
    91
    Thanks
    38

    Question How to set another QTableView in QDesigner-Layout?

    Hello!

    Just another problem...

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

    Qt Code:
    1. class Ui_AddressBook
    2. {
    3. public:
    4. QTableView *tableView;
    5. ...
    6.  
    7. void setupUi(QDialog *AddressBook)
    8. {
    9. ...
    10. tableView = new QTableView(AddressBook);
    11. tableView->setObjectName(QString::fromUtf8("tableView"));
    12. tableView->setGeometry(QRect(10, 10, 701, 191));
    13. ....
    14. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. AddressBook (inherits above class)
    2.  
    3. AddressBook::AddressBook(DataManager* dmgr, QWidget *parent): QDialog(parent)
    4. {
    5. setupUi(this); //here the "old" QTableView is set, see above
    6.  
    7. //customerTableView() belongs to my brandnew DataManager :)
    8. //it returns a QTableView with its model already set
    9. //I would like to display another QTableView here now:
    10. tableView = dmgr->customerTableView();
    11. //result is, that nothing is displayed in the box.
    12.  
    13. //if I add
    14. tableView.show(); //another small window opens, showing the correct data.
    15. }
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. delete tableView;
    To copy to clipboard, switch view to plain text mode 

    and set a new one?

    Kind regards,
    HomeR

  2. #2
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    6
    Thanked 18 Times in 18 Posts

    Default Re: How to set another QTableView in QDesigner-Layout?

    I dont't really get what you're doing , but I suggest you try:
    Qt Code:
    1. tableView = dmgr->customerTableView();
    2. tableView->setParent(this);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2010
    Posts
    91
    Thanks
    38

    Default Re: How to set another QTableView in QDesigner-Layout?

    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:
    Qt Code:
    1. DataManager* dmgr //manages data stuff
    2. Q_CHECK_PTR(dmgr);
    3. ...
    4. dmgr->customerTableView();//returns a QTableView*
    To copy to clipboard, switch view to plain text mode 

    datamanager.h

    Qt Code:
    1. private:
    2. QTableView *m_customerTableView;
    3. public:
    4. QTableView *customerTableView();
    To copy to clipboard, switch view to plain text mode 
    datamanager.cpp
    Qt Code:
    1. ...
    2. m_customerTableView = new QTableView;
    3. m_customerTableView->setModel(model_customer);
    4. ...
    5. QTableView *DataManager::customerTableView()
    6. {
    7. Q_ASSERT(m_customerTableView);
    8. return m_customerTableView; //returns QTableView with model set
    9. }
    To copy to clipboard, switch view to plain text mode 

    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: qt.jpg

    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

  4. #4
    Join Date
    Oct 2010
    Posts
    91
    Thanks
    38

    Default Re: How to set another QTableView in QDesigner-Layout?

    Everything is working fine if I just set the model to the
    one available from DataManager* dmgr .

    Qt Code:
    1. tableView->setModel(dmgr->customerModel());
    To copy to clipboard, switch view to plain text mode 

    but then I have to set all tableView-related things

    Qt Code:
    1. m_customerTableView->setObjectName("CustomerTableView");;
    2. m_customerTableView->setSortingEnabled(true);
    3. m_customerTableView->sortByColumn(0, Qt::DescendingOrder);
    4. m_customerTableView->setSelectionMode(QAbstractItemView::SingleSelection);
    5. m_customerTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    6. selectionModelCustomer = new QItemSelectionModel(model_customer);
    7. m_customerTableView->setSelectionModel(selectionModelCustomer);
    8. headerViewCustomer = m_customerTableView->horizontalHeader();
    To copy to clipboard, switch view to plain text mode 

    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.

    Qt Code:
    1. Q_CHECK_PTR(dmgr->customerTableView());
    2. tableView = dmgr->customerTableView();
    3. out << "tableViewName: " << tableView->objectName() << "\n";
    To copy to clipboard, switch view to plain text mode 

    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

Similar Threads

  1. Using QDesigner Plugin
    By fakefish in forum Installation and Deployment
    Replies: 3
    Last Post: 9th December 2010, 16:37
  2. QDesigner plugin
    By h123 in forum Qt Programming
    Replies: 4
    Last Post: 12th October 2009, 08:36
  3. QTableView - model / view pattern - layout, edit
    By vlastagf in forum Qt Programming
    Replies: 4
    Last Post: 1st August 2009, 23:42
  4. QDesigner + Qtranslator + QComboBox
    By Atikae in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2008, 16:41
  5. QDesigner classes for Arm platform
    By vjn in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 10th April 2008, 17:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.