Results 1 to 9 of 9

Thread: QTableview data display font question

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default QTableview data display font question

    How to change qtableview data display font?
    Qt 5.3 Opensource & Creator 3.1.2

  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: QTableview data display font question

    Use QWidget::setFont() or make your model return the desired font for Qt::FontRole.
    J-P Nurmi

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

    MarkoSan (14th May 2008)

  4. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTableview data display font question

    Quote Originally Posted by jpn View Post
    Use QWidget::setFont() or make your model return the desired font for Qt::FontRole.
    jpn, I've set the font using setFont(), but now the cell does not resize automaticly!!! How do I resize a cell acoording to font size? Do you have maybe some example?
    Qt 5.3 Opensource & Creator 3.1.2

  5. #4
    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: QTableview data display font question

    What about the other solution?
    J-P Nurmi

  6. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTableview data display font question

    I have no idea how to achieve that ...
    Qt 5.3 Opensource & Creator 3.1.2

  7. #6
    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: QTableview data display font question

    You said you have QTableView so you have a model too, right? QAbstractItemModel::data() returns data for various roles. Qt::FontRole is one of them.
    J-P Nurmi

  8. #7
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTableview data display font question

    I have:

    • class, subclassed from QTableView (my view)
    • class, subclassed from QStandardItemModel (my model)
    • class, subclassed from QItemDelegate (my delegate)

    How do I get to this font role?
    Qt 5.3 Opensource & Creator 3.1.2

  9. #8
    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: QTableview data display font question

    Qt Code:
    1. QVariant MyCustomModel::data(const QModelIndex& index, int role) const
    2. {
    3. if (index.isValid() && role == Qt::FontRole)
    4. return QFont(...);
    5.  
    6. return QStandardItemModel::data(index, role);
    7. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  10. The following 2 users say thank you to jpn for this useful post:

    diegoshaman (29th November 2013), MarkoSan (14th May 2008)

  11. #9
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTableview data display font question

    Well, this is my code for data() function:
    Qt Code:
    1. QVariant CShoppingCartModel::data(const QModelIndex &index, int role) const
    2. {
    3. if(index.isValid() && role==Qt::EditRole)
    4. return m_pMerchandizeOrder->orders()->at(index.row()).strDisplayString;
    5. //QStandardItemModel::data(index, role);
    6. if(index.isValid() && role==Qt::FontRole)
    7. return QFont("Courier New", 24, QFont::Bold);
    8. return QVariant(); // returns invalid record
    9. }
    To copy to clipboard, switch view to plain text mode 

    And the result is still the same, the cell size is not updated. What is still missing?
    Last edited by MarkoSan; 14th May 2008 at 19:02. Reason: updated contents
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. First attempt to display serial port data on GUI
    By ShaChris23 in forum Newbie
    Replies: 12
    Last Post: 4th May 2007, 10:14

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.