Results 1 to 7 of 7

Thread: Problems customizing tooltips in QListView

  1. #1
    Join Date
    Mar 2006
    Posts
    56
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Problems customizing tooltips in QListView

    I have a problem customizing tooltips for QListView.

    I had to add a custom tooltip object to my list view in order to show some information when the cursor is over some columns in the list view.

    For the other columns I want the default behavior, I mean show the tooltip with the cell text if the text is truncated.

    The problem is that the new tooltip object override the default one. I tried to use in the maybetip function of my custom tooltip the code of the tooltip in the QListView class, but it accesses some private fields of the QListViewItem in order to determine whether the text is truncated.

    I tried also to use the following code to determine whether the text is truncated

    Qt Code:
    1. ...
    2. if( view->header()->sectionSize( colIndex ) < item->width( view->fontMetrics(), view, colIndex ) )
    3. tip( rect, item->text(colIndex) );
    4. ...
    To copy to clipboard, switch view to plain text mode 

    it is working for all the columns except for the first one, because it does not take into account the box size of the QCheckListItem, the decorator size (+ or -) and the depth of the item.

    Thanks in advance for your suggestions!

  2. #2
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems customizing tooltips in QListView

    Are you using the Model-View-Concept?
    In this case you have full control over the tooltip.
    In you implementaion of the model method data() you can return your tooltip-string for the displayrole Qt::ToolTipRole.

    You can even have different tooltips on each cell.

    Good luck - let us know if you need more info.

  3. #3
    Join Date
    Mar 2006
    Posts
    56
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems customizing tooltips in QListView

    I think you are talking about Qt 4... Unfortunately I'm working with Qt3

  4. #4
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems customizing tooltips in QListView

    Ooops ....

    I'm sorry - didn't look close enough ....

    You need to upgrade than (<--- joke!!!)

  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: Problems customizing tooltips in QListView

    Did you try using QListView::columnWidth(int) to fetch the column width and QListView::itemAt() to determine which item is under cursor?

  6. #6
    Join Date
    Mar 2006
    Posts
    56
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems customizing tooltips in QListView

    Quote Originally Posted by wysota View Post
    Did you try using QListView::columnWidth(int) to fetch the column width and QListView::itemAt() to determine which item is under cursor?
    Qt Code:
    1. view->header()->sectionSize( colIndex )
    To copy to clipboard, switch view to plain text mode 

    is a similar way to find the size of the column.
    The problem is that other than the size of the column I need to know the width needed by the item to be drawn in such column.

    The width needed by the cell in the first column of an item is determined by:
    • The Text size (known)

    • The Pixmap size (known)

    • The size of the decorator of the QCheckListItem (unknown)

    • The size of the box of the QCheckListItem (unknown)

    • The indentation of the QChecklist item (if the item is child of other items the first column is indented) (unknown)


    I do not know how to compute the size of the unknown elements

  7. #7
    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: Problems customizing tooltips in QListView

    Quote Originally Posted by kalos80 View Post
    I do not know how to compute the size of the unknown elements
    The elements are drawn according to the style. You can query the active style for the size. It's possible that you can query for the complete size you need. Just take a look at what QStyle offers.

Similar Threads

  1. Problems customizing QSlider
    By Antrax in forum Qt Programming
    Replies: 13
    Last Post: 20th December 2011, 07:00

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.