Results 1 to 3 of 3

Thread: QTableView invisible content

  1. #1
    Join Date
    Dec 2010
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QTableView invisible content

    I'm want to use a QTableView with a QSqlTabkeModel. The table's content is invisible after seting up the model.
    The QTableView widget is created in designer.

    initalizeModel test method is from http://doc.qt.nokia.com/stable/sql-tablemodel.html
    Qt Code:
    1. void DatabaseWindow::initializeModel()
    2. {
    3. mDataTableModel->setTable("person");
    4. mDataTableModel->setEditStrategy(QSqlTableModel::OnRowChange);
    5. mDataTableModel->select();
    6.  
    7. mDataTableModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
    8. mDataTableModel->setHeaderData(1, Qt::Horizontal, QObject::tr("First name"));
    9. mDataTableModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Last name"));
    10.  
    11. //here i call ExtendedTableWidget's setUpView method
    12. mTableWidget->setUpView(mDataTableModel);
    13. }
    To copy to clipboard, switch view to plain text mode 

    header:
    Qt Code:
    1. namespace Ui
    2. {
    3. class ExtendedTableWidget;
    4. }
    5.  
    6. class ExtendedTableWidget : public QWidget
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit ExtendedTableWidget(QWidget *parent = 0);
    11.  
    12. void setUpView(QSqlTableModel *model);
    13.  
    14. private:
    15.  
    16. private:
    17. Ui::ExtendedTableWidget *mUi;
    18. };
    To copy to clipboard, switch view to plain text mode 

    cpp:
    Qt Code:
    1. #include "extendedtablewidget.h"
    2. #include "ui_extendedtablewidget.h"
    3.  
    4. ExtendedTableWidget::ExtendedTableWidget(QWidget *parent) :
    5. QWidget(parent),
    6. mUi(new Ui::ExtendedTableWidget())
    7. {
    8. mUi->setupUi(this);
    9. }
    10.  
    11. void ExtendedTableWidget::setUpView(QSqlTableModel *model)
    12. {
    13. mUi->tableMainData->setModel(model);
    14. mUi->tableMainData->setSelectionModel(new QItemSelectionModel(model));
    15.  
    16. //the tpmTable is show the content, but tableMainData isn't
    17.  
    18. QTableView *tpmTable = new QTableView();
    19.  
    20. tpmTable.setModel(model);
    21. tpmTable.show();
    22. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableView invisible content

    is the model set up correctly? can you access any data in the model? Also maybe do you delete the model before the view is shown? Also where do you set the database for your model?

  3. #3
    Join Date
    Dec 2010
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView invisible content

    Ty for fast replay!

    I recreated the "tableMainData"(QTableView) in designer and it is working well now. The previous "tableMainData"(QTableView) was morphed from QTableWidget.

  4. The following user says thank you to danczer for this useful post:

    Aslan (23rd January 2011)

Similar Threads

  1. Replies: 4
    Last Post: 18th March 2010, 11:11
  2. QTableView header invisible
    By smacchia in forum Qt Programming
    Replies: 7
    Last Post: 20th November 2009, 04:21
  3. QTableView column header is invisible
    By grsandeep85 in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2009, 13:04
  4. Replies: 5
    Last Post: 24th July 2009, 23:30
  5. [qt3]invisible toolbar
    By lszk in forum Qt Programming
    Replies: 2
    Last Post: 26th February 2006, 19:34

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.