Results 1 to 7 of 7

Thread: QTableView with custom QHeaderView

  1. #1
    Join Date
    Sep 2007
    Posts
    7
    Thanked 1 Time in 1 Post

    Default QTableView with custom QHeaderView

    hi,

    is there a way to write a custom table header which takes into account grouped collumns? say i have colums like Input1, Input2, Input3, and Output1, Output2, which should be grouped by Inputs and Outputs. the table header should then have 2 rows and look like this:
    _________________________________________
    |________Inputs________|______Outputs_____|
    | Input1 | Input2 | Input3 | Output1 | Output2 |

    clicking at Inputs should select all Input collums, clicking on Input1 only Input1 ans so on.

    does anyone have an idea how this could be done.

    greetings.

  2. #2
    Join Date
    Sep 2007
    Posts
    7
    Thanked 1 Time in 1 Post

    Default Re: QTableView with custom QHeaderView

    nobody i guess.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView with custom QHeaderView

    Yes, there is a way You have to implement your own QHeaderView subclass and implement the functionality you want.

  4. #4
    Join Date
    Sep 2007
    Posts
    7
    Thanked 1 Time in 1 Post

    Default Re: QTableView with custom QHeaderView

    yeah right but how exactly? i guess i have to rewrite the whole drawing capabilitys like paintEvent and paintSection. any idea where to start?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView with custom QHeaderView

    You'll have to implement half of the functionality from the abstract view. Things like index positions, etc. Practically all you can take from QHeaderView is the inheritance, so that you can use it with a table view. But it might be inpractical (you'll have to reimplement some of the table view functionality as well). It might be easier to instead implement your own header (for example composited from two or more QHeaderView instances) and couple it with the table.

  6. #6
    Join Date
    Sep 2007
    Posts
    7
    Thanked 1 Time in 1 Post

    Default Re: QTableView with custom QHeaderView

    i have started with reimplementing paintEvent ( QPaintEvent * event ) but when i try to create a QPainter as shown in the documentation the console says:

    QPainter::begin: Widget painting can only begin as a result of a paintEvent

    but it is inside paint event.

    code

    HeaderView::HeaderView(Qt::Orientation orientation, QWidget * parent) : QHeaderView(orientation, parent)
    {
    }


    void HeaderView::paintEvent ( QPaintEvent * event )
    {
    QPainter painter(this);
    painter.drawRect(event->rect());
    }

    any idea?

  7. #7
    Join Date
    Sep 2007
    Posts
    7
    Thanked 1 Time in 1 Post

    Default Re: QTableView with custom QHeaderView

    ok this problem is solved. used

    QPainter painter(viewport());
    instead.

    will try to reimplement the QHeaderView. if anyone has an idea on how this could be done otherwhise let me know please. i thought letting table items be tables of its own so that one would automaticly have more headers. the only problem is then how to sort and how to design in model/view architekture. any advices?

    tnx

Similar Threads

  1. Advanced QTableView
    By jpujolf in forum Qt Programming
    Replies: 13
    Last Post: 17th April 2010, 09:15
  2. Custom QHeaderView in Qt 4.1.1
    By Tair in forum Qt Programming
    Replies: 2
    Last Post: 11th July 2006, 09:44

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.