Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Text and Icon in QTableView header
Servers for Qt installer are currently down

Text and Icon in QTableView header

Scheduled Pinned Locked Moved General and Desktop
qtableview
3 Posts 3 Posters 6.7k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aornic
    wrote on 11 May 2015, 09:39 last edited by
    #1

    Hi,

    I would like to have text and icons in the horizontal header of QTableView.
    With the following code I can display text header but I don't know how to add icons to each text:

       m_modelo = new QSqlRelationalTableModel(this);	
    m_modelo->setTable("tablename");
    m_modelo->setEditStrategy(QSqlTableModel::OnManualSubmit);	
    m_modelo->setHeaderData(1, Qt::Horizontal,tr("ORDER"));
    m_modelo->setHeaderData(2, Qt::Horizontal,tr("PLAYER"));
    m_modelo->setHeaderData(3, Qt::Horizontal,tr("NUMBER"));
    m_modelo->setSort(1, Qt::AscendingOrder);
    m_modelo->select();	
    m_ui.tableview->setModel(m_modelo);
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mistralegna
      wrote on 11 May 2015, 11:07 last edited by
      #2

      Suppose you want to add an icon to the very first column (first section - index 0 - of horizontal headers).

      m_modelo->setHeaderData(0, Qt::Horizontal, QVariant::fromValue(QIcon("path/to/icon")), Qt::DecorationRole);
      

      You can adapt the code by adjusting either the targeted section (i.e. the column or the row depending on the context) or the targeted header (depending on the given orientation parameter).

      K 1 Reply Last reply 15 Aug 2024, 13:23
      2
      • M mistralegna
        11 May 2015, 11:07

        Suppose you want to add an icon to the very first column (first section - index 0 - of horizontal headers).

        m_modelo->setHeaderData(0, Qt::Horizontal, QVariant::fromValue(QIcon("path/to/icon")), Qt::DecorationRole);
        

        You can adapt the code by adjusting either the targeted section (i.e. the column or the row depending on the context) or the targeted header (depending on the given orientation parameter).

        K Offline
        K Offline
        Kaguro
        wrote on 15 Aug 2024, 13:23 last edited by Kaguro
        #3

        @mistralegna And how can i resize the icon ?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved