Results 1 to 8 of 8

Thread: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    3

    Question Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?

    Hi,

    I have a QTableView bound to a QSqlTableModel.

    I'm strugling to find a way to change the row (that's the vertical) headers. Is there any way to do that? And how?

    A Singer

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

    Default Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?

    Subclass the model and reimplement its headerData() method.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Avrohom (12th May 2009)

  4. #3
    Join Date
    Jan 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    3

    Angry Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?

    Thanks for your help. I've tried it, and works fine. However, when trying to return a QSize on role == Qt::SizeHintRole the application crashes.

    Any suggestion?

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

    Default Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?

    It shouldn't crash (meaning your code is probably wrong) although returning a size hint role for the header has no effect as the size of the header is controlled by the size of the data cells.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Jan 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    3

    Post Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?

    Thanks. OK, as someone that tries to learn QT I will dig into the code to find out what I have done wrong. But how do I set the cell's width then?

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?

    Look at QHeaderView API.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Jan 2009
    Posts
    14
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    3

    Post Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?

    Dear Wysota,

    Thanks for the help. Before checking out on that api, I thought you might be interested in the following.

    First, I found out what was causing my application to crash, and that was that I haven't provided a default return value i.e. for values that didn't match any of the tested scenarios in the headerData implementation.

    Second, after fixing that bug, I found out that, returning a QSize value in the headerData implementation where role == Qt:SizeHintRole has definitely an effect on the cell size. So this one is also solved.

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Newbie Question: Can I change vertical (row) headers on a QSqlTableModel?

    Quote Originally Posted by Avrohom View Post
    Second, after fixing that bug, I found out that, returning a QSize value in the headerData implementation where role == Qt:SizeHintRole has definitely an effect on the cell size. So this one is also solved.
    Just be aware this might be overridden by items themselves.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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
  •  
Qt is a trademark of The Qt Company.