Results 1 to 2 of 2

Thread: Can I have a qwidget in the headerData of a Table?

  1. #1
    Join Date
    Nov 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Can I have a qwidget in the headerData of a Table?

    I would like to have a checkbox in the (column) headers in a QTableView() that I use, in order to mark certain columns. The model that I use is a QSqlTableModel. However, I can't find a way to do that.
    Maybe somebody knows the trick?

    Regards,
    Bertwim

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Can I have a qwidget in the headerData of a Table?

    I've added a combo box to the header of a QTableWidget. I assume it works similar with a QTableView. Here's an outline of what I've done:
    - Create a new class MyHeaderView derived from QHeaderView
    - In the CTOR of MyHeaderView, I create a new QComboBox with the header view viewport as parent:
    new QComboBox(viewport())
    - In the CTOR, connect QHeaderView signal sectionResized(int,int,int) to a slot onSectionResized(int,int,int) of the new class
    MyHeaderView. This slot is responsible for moving my combo box to the right place and resize it in case that the section
    size changes.
    - Implement onSectionResized(int section, int oldSize, int newSize) in class MyHeaderView. In my implementation, I use
    QSize s = sectionSizeFromContents(section) to get width and height.
    For moving the combo box, I use sectionViewportPosition(section) to determine the section start position.

    Hope this will help you a little bit.

Similar Threads

  1. QTableView and headerData
    By xyfix in forum Qt Programming
    Replies: 1
    Last Post: 13th May 2010, 09:15
  2. Replies: 0
    Last Post: 8th July 2009, 11:01
  3. QTableView headerData() color
    By starcontrol in forum Qt Programming
    Replies: 5
    Last Post: 16th April 2008, 14:04
  4. How to remove the treeView HeaderData
    By Kostanev in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2008, 08:45
  5. QTreeView HeaderData StyleSheet
    By Kostanev in forum Qt Programming
    Replies: 2
    Last Post: 12th September 2007, 22:12

Tags for this Thread

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.