Results 1 to 4 of 4

Thread: show User Defined Header Labels in QTableView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: show User Defined Header Labels in QTableView

    I wanted to put the Header Names which i have defined on the Top Horizontal Header, instead of the horizontal header names which are column names of the sql table. . i have all the names which i want in a QStringList. i looked a lot but din find a solution. .. can any one pls tell me how to go about it.

  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

    Post Re: show User Defined Header Labels in QTableView

    setHorizontalHeaderLabels requires a QStringList, furthermore make sure you set the labels after the model is populated. And I guess you have to set the labels everytime you change the query.

    EDIT: or make it, like the documentation tells:
    Qt Code:
    1. model->setQuery("SELECT name, salary FROM employee");
    2. model->setHeaderData(0, Qt::Horizontal, tr("Name"));
    3. model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
    4.  
    5. QTableView *view = new QTableView;
    6. view->setModel(model);
    7. view->show();
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lykurg for this useful post:

    nagabathula (11th August 2011)

  4. #3
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: show User Defined Header Labels in QTableView

    Hello Lykurg your example helped me solve my problem.. This is what i did to display the Header Labels which i have defined.

    Qt Code:
    1. for(int i=0; i<thermoNames.count(); i++)
    2. {
    3. model->setHeaderData( i, Qt::Horizontal,thermoNames.at(i));
    4. }
    To copy to clipboard, switch view to plain text mode 

    thank you

Similar Threads

  1. Cannot see the header labels SQL
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 2
    Last Post: 27th June 2011, 01:38
  2. How to get user-defined message?
    By ponponfish in forum Qt Programming
    Replies: 3
    Last Post: 17th May 2011, 16:19
  3. Replies: 10
    Last Post: 6th April 2011, 10:05
  4. Using User Defined Libraries
    By csvivek in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2008, 19:47
  5. User Defined Signal?
    By rajeshs in forum Newbie
    Replies: 2
    Last Post: 18th December 2007, 11:42

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.