Results 1 to 2 of 2

Thread: QTreeView mouse hovering over custom cell selects row

  1. #1
    Join Date
    Apr 2019
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default QTreeView mouse hovering over custom cell selects row

    Hi,

    I am working now with QT for a year but I am new to this board. I googled this issue but it seems as i am the only only one who ran into this, therefore looking for an expert here for an explanation / a solution.

    I designed several Dialogs with 2 QTreeViews. The right tree basically shows the detailed view of the selected item in the left tree.

    In 2 of those Dialogs there is a 'favourite' column. The user can click on a star icon to add/remove the item to/from a favourite list. In order to change the checkbox to the before mentioned star icon, i had to insert a QCheckbox via insertWidget into the cell, because i could'nt customize the built in checkbox through css (the star never appeared -> https://stackoverflow.com/questions/...ew-doesnt-show). Now the star-Checkbox works but there is an issue that only occurs with these 'special' cells.

    For every other cell that contains a checkbox i just used the built in functionality (setCheckable(true)) and they work as intended without any misbehaviour. The special cells however get selected when the mouse hovers over that, but only once and only after another line was selected before. It behaves very strange, when hovering over the favourite column it does select the row but it does not call the selectionChanged function but getSelectedIndexes yields the wrongly selected row the mouse hovered over.

    Does anyone have a clue why this is happening and how to prevent it? I overrode mouseMoveEvent of the QTreeView and it actually prevented this from happening, but at the same time disabled any drag&drop on it, so thats not a real solution.

    Another issue i have is that i cant center the custom checkbox in the cell. I use a custom delegate which overrides the paint function to center checkboxes and it works well on the standardItems which are set chackable, but the cutom checkbox stays fixed at the left side of the cell ( i tried centering it with css 'margin: auto;' but it didnt have an effect).

    Any hint is appreciated, tell me if you need more details.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView mouse hovering over custom cell selects row

    Adding widgets to item views is always tricky as they have their own event handling and painting.

    I guess in this case, where you only want to change how the "checkable" state is draw, it might be better to use a custom delegate that does just that.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 10th March 2014, 13:25
  2. Changing the mouse button which selects items
    By Rikonator in forum Newbie
    Replies: 4
    Last Post: 9th August 2011, 19:36
  3. Replies: 1
    Last Post: 14th February 2011, 00:23
  4. Replies: 1
    Last Post: 12th October 2010, 23:20
  5. Mouse hovering or press event not working?
    By qtzcute in forum Newbie
    Replies: 11
    Last Post: 15th July 2009, 11:53

Tags for this Thread

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.