Results 1 to 3 of 3

Thread: Text in QTableView cells not visible

  1. #1
    Join Date
    Mar 2007
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Text in QTableView cells not visible

    Hello everyone, I have a problem with displaying item text in QTableView.
    I created a QTableView widget using QT Designer and I am trying to make it dsplay a model.
    I've created a model and set it to a view, the view doesn't display the text of the items, though it does show the same amount of empty columns and rows as the model contains. For example, I do this:


    ui.setupUi((QMainWindow *)this);
    QStandardItemModel model(2, 2);
    QString st;
    st.append("whee");
    QStandardItem *item = new QStandardItem(st);
    item->setText(st);
    model.setItem(0, 0, item);
    QStandardItem * item2 = model.item(0,0);
    QString st2 = item2->text();

    ui.tableView->setModel(&model);
    ui.tableView->show();

    The item text is getting returned correctly, but I can't see this text in a cell. What am I doing wrong?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Text in QTableView cells not visible

    Quote Originally Posted by juliarg View Post
    The item text is getting returned correctly, but I can't see this text in a cell. What am I doing wrong?
    The model goes out of the scope and is destroyed as soon as the constructor ends. Create the model with operator "new".
    J-P Nurmi

  3. #3
    Join Date
    Mar 2007
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Text in QTableView cells not visible

    Thanks for pointing that out! What a stupid bug

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30
  3. Editable cells in QTableView
    By TheRonin in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2006, 17:39
  4. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 09:02
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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.