Results 1 to 7 of 7

Thread: Multi-line messages in QTableView

  1. #1
    Join Date
    Apr 2006
    Location
    Minsk, Belarus
    Posts
    33
    Thanks
    2
    Thanked 6 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Multi-line messages in QTableView

    I use QTableView to show data contained in my LogsModel (which inherits QAbstractTableModel). In order to enable sorting and filtering I use QSortFilterProxyModel as a proxy between LogsModel and QTableView. LogsModel is refreshed from time to time (it takes additional items from the database)

    Now the problem is that my model can contain multi-line text strings. In that case I have the following problem with displaying these messages: I can see only the bottom of the first line and the top of the second line (in case of 2-lined message)

    This issue can be easily solved if I invoke method resizeRowToContents(int i) of QTableView class. But the problem is that table is refreshed from time to time (when changing sorting order, or when filter is applied, or some new items appear in LogsModel). So every time it refreshes I should resize all the rows in the table (because I don't know exact place where new rows have appeared). But this is very time-consuming because table may contain thousands rows.

    So, the question is: how to make multi-line message fully visible in QTableView taking into account all that I said before.

    Probably I can resize only currently visible rows. In this respect my question is: how can I get to know which rows of the QTableView are currently visible?

  2. #2
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Multi-line messages in QTableView

    This is a known bug in both 4.0.1 and 4.1.1

    Use either 4.1.0 or 4.1.2 to fix this.

    See also this thread.
    Life without passion is death in disguise

  3. #3
    Join Date
    Apr 2006
    Location
    Minsk, Belarus
    Posts
    33
    Thanks
    2
    Thanked 6 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Multi-line messages in QTableView

    Thanks for the info. The problem is that for QTreeView this issue is fixed but not for QTableView. I'm using Qt 4.1.2 and for different source code I have different results

    Qt Code:
    1. #include <QApplication>
    2. #include <QTableView>
    3. #include <QTreeView>
    4. #include <QStandardItemModel>
    5. int main(int argc, char **argv)
    6. {
    7. QApplication app(argc, argv);
    8. QTreeView view;
    9. // Prepend 4 rows into the model
    10. model->insertRows(0, 4);
    11. // Prepend 4 columns into the model
    12. model->insertColumns(0, 4);
    13. for (int row = 0; row < 4; row++)
    14. {
    15. for (int col = 0; col < 4; col++)
    16. {
    17. // Return a model index for the given row and column.
    18. QModelIndex index = model->index(row, col);
    19. // Set the index's data to the specified value
    20. model->setData(index, QVariant("hello\nnextline\nonemoreline"));
    21. }
    22. }
    23. view.setModel(model);
    24. view.show();
    25. return app.exec();
    26. }
    To copy to clipboard, switch view to plain text mode 

    Here the result:
    QTreeView_example.jpg

    Now I'm changing only one line: QTreeView is replaced with QTableView

    Qt Code:
    1. #include <QApplication>
    2. #include <QTableView>
    3. #include <QTreeView>
    4. #include <QStandardItemModel>
    5. int main(int argc, char **argv)
    6. {
    7. QApplication app(argc, argv);
    8. QTableView view;
    9. // Prepend 4 rows into the model
    10. model->insertRows(0, 4);
    11. // Prepend 4 columns into the model
    12. model->insertColumns(0, 4);
    13. for (int row = 0; row < 4; row++)
    14. {
    15. for (int col = 0; col < 4; col++)
    16. {
    17. // Return a model index for the given row and column.
    18. QModelIndex index = model->index(row, col);
    19. // Set the index's data to the specified value
    20. model->setData(index, QVariant("hello\nnextline\nonemoreline"));
    21. }
    22. }
    23. view.setModel(model);
    24. view.show();
    25. return app.exec();
    26. }
    To copy to clipboard, switch view to plain text mode 

    And now I have the wrong output:
    QTableView_example.jpg

    Do you think I should send this as a bug to Trolltech?

  4. #4
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Multi-line messages in QTableView

    Yeah, I think they must not have fixed the problem fully yet. Check to see if someone already has an active bug submitted, and if not tell the Trolls exactly what you said here (very good detail).
    Life without passion is death in disguise

  5. The following user says thank you to KShots for this useful post:

    Conel (12th April 2006)

  6. #5
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Multi-line messages in QTableView

    Have you tried resizeRowsToContents()?

  7. #6
    Join Date
    Apr 2006
    Location
    Minsk, Belarus
    Posts
    33
    Thanks
    2
    Thanked 6 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Multi-line messages in QTableView

    Yes, I did. Invoking method reziseRowsToContents() makes multiline messages fully visible but this does not suit my needs. I use QTableView with my own model which takes items from the database and refreshes quite often. Since I also use QSortFilterProxyModel I can't predict where updated rows will appear. So every time I refresh the model I should invoke resize method for all rows in the table. Since the table may contain thousands of rows this is very time-consuming. So this workaround can not be applied here

  8. #7
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Multi-line messages in QTableView

    Not only that, but he shouldn't have to fix TT bugs in his code. Much better for everyone if TT fixes this - they've already determined that such behaviour is a bug on their part.
    Life without passion is death in disguise

Similar Threads

  1. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 14:51
  2. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 17:48
  3. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 10:16
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 19:42

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.