Results 1 to 2 of 2

Thread: QTableView Headers problem

  1. #1
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTableView Headers problem

    Hey guy!
    I have a very simple problem:
    I display data of an sqlite database in an sqltablemodel + qtableview.

    Qt Code:
    1. void DatiPannello::setDatabase(const QSqlDatabase &db,const QString &t)
    2. {
    3. database = db;
    4. table = t;
    5. if (model){
    6. delete model;
    7. model = new QSqlTableModel(0,database);
    8. }
    9.  
    10. initializeModel();
    11. refreshView();
    12. }
    13. void DatiPannello::refreshView()
    14. {
    15. model->setTable(table);
    16.  
    17. model->select();
    18.  
    19. proxyModel->setSourceModel(model);
    20.  
    21. tViewDatiPannello->setModel(proxyModel);
    22.  
    23. tViewDatiPannello->setColumnHidden(0,true);
    24.  
    25.  
    26.  
    27. }
    28. void DatiPannello::initializeModel()
    29. {
    30. if (model) {
    31. model->setTable(table);
    32. model->setEditStrategy(QSqlTableModel::OnRowChange);
    33. model->select();
    34.  
    35.  
    36. model->setHeaderData(1, Qt::Horizontal, tr("Marca"),Qt:: DisplayRole);
    37. model->setHeaderData(2, Qt::Horizontal, QObject::tr("Modello"));
    38. model->setHeaderData(3, Qt::Horizontal, tr("Pnom"));
    39. model->setHeaderData(4, Qt::Horizontal, tr("Voc"));
    40. model->setHeaderData(5, Qt::Horizontal, tr("Isc"));
    41. model->setHeaderData(6, Qt::Horizontal, tr("Imp"));
    42. model->setHeaderData(7, Qt::Horizontal, tr("NOCT"));
    43. model->setHeaderData(8, Qt::Horizontal, tr("Peso"));
    44. model->setHeaderData(9, Qt::Horizontal, tr("Vmp"));
    45. model->setHeaderData(10, Qt::Horizontal, tr("Vmax"));
    46. model->setHeaderData(11, Qt::Horizontal, tr("beta"));
    47. model->setHeaderData(12, Qt::Horizontal, tr("alfa"));
    48. model->setHeaderData(13, Qt::Horizontal, tr("gamma"));
    49. model->setHeaderData(14, Qt::Horizontal, tr("tol."));
    50. model->setHeaderData(15, Qt::Horizontal, tr("H"));
    51. model->setHeaderData(16, Qt::Horizontal, tr("L"));
    52. model->setHeaderData(17, Qt::Horizontal, tr("s"));
    53. model->setHeaderData(18, Qt::Horizontal, tr("efficienza"));
    54.  
    55.  
    56. }
    57.  
    58.  
    59.  
    60.  
    61. }
    To copy to clipboard, switch view to plain text mode 
    but I never get the header I set, I get the name of the columns in the database!
    Any help, as always, rellay appreciated.

  2. #2
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView Headers problem

    Hi,

    See my source code, I think that will can help.

    Note that the 'setHeaderData' always should be between the 'select' statement. and setModel().

    Qt Code:
    1. QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    2. model->setQuery("SELECT LPAD(PV_IDENT,5,'0') AS PV_IDENT, PV_NOME, CONCAT_WS(' ',sys.spISO2EUR(LEFT(PV_DATA,10)),RIGHT(PV_DATA,8) ) AS PV_DATA, PV_OBJ FROM ACPEDVISTA WHERE PV_FLAG = 0 ORDER BY PV_DATA");
    3. model->setHeaderData(0, Qt::Horizontal, tr("Id#"));
    4. model->setHeaderData(1, Qt::Horizontal, tr("Requisitante"));
    5. model->setHeaderData(2, Qt::Horizontal, tr("Data"));
    6. model->setHeaderData(3, Qt::Horizontal, tr("Objeto"));
    7.  
    8. tviewPedidos->setModel(model);
    9. tviewPedidos->show();
    10. QApplication::restoreOverrideCursor();
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 23rd January 2009 at 11:12. Reason: missing [code] tags

Similar Threads

  1. spaning the headers in the QTableView
    By ru_core in forum Qt Programming
    Replies: 6
    Last Post: 11th June 2013, 13:17
  2. How to remove headers from QTableView.
    By rajeshs in forum Qt Programming
    Replies: 7
    Last Post: 18th November 2011, 20:00
  3. Problem with KeyPress event and QTableView
    By ranna in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 20:01
  4. Problem with QTableView
    By BoneCollector in forum Qt Programming
    Replies: 5
    Last Post: 12th March 2008, 12:30
  5. QTableView : headers disappear
    By xavier in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2006, 16:57

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.