Results 1 to 4 of 4

Thread: QTableView Custom Item Approach

  1. #1
    Join Date
    Jul 2018
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default QTableView Custom Item Approach

    Not sure what "Beginner" means, I have been using Qt for many years

    I have a working QTableView with QSqlRelationalTableModel and custom QHeaderView that functions well but without the two features shown in the attached image.
    Namely:
    1. the "expanded view" between rows 3 and 4 (row 3 selected)
    2. the "Session" grouping shown at line 9 (that requires drag-n-drop functionality to "ungroup" items)


    I am aware of classes such as QAbstractTableModel, but have extremely limited experience with them.
    I am thinking that what is required is a custom QSqlRelationalDelegate but the documentation for it would suggest that it is intended for items (column data) rather than rows.

    I was considering a QTableWidget with custom QTableWidgetItems, (which I have experience with), but I currently enjoy the benefits of the great integration of the QTableView, QSqlRelationalTableModel and custom QHeaderView that works so well...

    I would like some suggested approaches to providing the missing functionality.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,385
    Thanks
    247
    Thanked 687 Times in 677 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QTableView Custom Item Approach

    Not sure what "Beginner" means, I have been using Qt for many years
    How is the forum software to know that? It only knows how long and how often you've posted or replied to posts. With one post, you're a Beginner.

    As for your requirement, it is difficult to see from your screenshot whether what you are showing is an expanded detail view of the selected row or whether it is a widget that overlays the table. There is a commercial product, QTitanDataGrid, that supports the first concept, of an expanded detail view. I've never used it but it seems to have some interesting features. If what you want is simply an overlay, then you could pop up a QWidget-based modal widget containing the details, positioned such that it sits under the selected row. There isn't anything in the off-the-shelf QTableView to support either of these, so you'd have to write (or buy) it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2018
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTableView Custom Item Approach

    Quote Originally Posted by d_stranz View Post
    How is the forum software to know that?
    Well thanks, now I know that "beginner" refers to my (lack of) time spent on forum and not Qt experience.

    Perhaps my lack of forum etiquette also prevents me from understanding why you cannot see the "screenshot" clearly.
    When I click on my posts' attached thumbnail I can see it clearly.

    Quote Originally Posted by d_stranz View Post
    There isn't anything in the off-the-shelf QTableView to support either of these, so you'd have to write (or buy) it.
    Well yes, that is why I was asking for suggested approaches to writing it myself. Or maybe my post was not clear about that.

    When using a QTableWidget, you can create custom table items by sub-classing QTableWidgetItems.
    I have implemented many such solutions.
    I am merely trying to find a similar solution for QTableView.

    I am inclined to think the solution involves a custom delegate.

    NOTE:
    The data displayed is not editable (with one exception). It is just a consolidated view of a combination of data tables.
    And the view is row oriented rather than spreadsheet oriented
    The exception is that (in the second case) items may be dragged out of the parent item (labeled "Session") to become normal items.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,385
    Thanks
    247
    Thanked 687 Times in 677 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QTableView Custom Item Approach

    The image was smallish and not very legible on my 4K monitor, so it is not easy to tell what it is you are trying to display. It's a problem I have with many of the images posted here.

    My understanding of item delegates is that they are displayed within the rectangle bounds of the table cell. What you are showing in the center of your screenshot seems to be sized and positioned independently of any particular cell. If you do use a delegate, maybe you can play with paint(), sizeHint(), and clipping to achieve what you want.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 15
    Last Post: 31st January 2020, 17:54
  2. Replies: 1
    Last Post: 20th January 2015, 17:49
  3. Replies: 1
    Last Post: 6th December 2013, 20:08
  4. Replies: 13
    Last Post: 6th May 2011, 10:34
  5. Best (and easiest) approach, QCombobox and QTableView...
    By scott_hollen in forum Qt Programming
    Replies: 2
    Last Post: 29th March 2011, 14:07

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.