Results 1 to 2 of 2

Thread: Tree Model with checkboxes click determination

  1. #1

    Default Tree Model with checkboxes click determination

    I have made TreeModel which extends QAbstractItemModel.
    Created checkboxes on the first column.
    Click on the row causes opening new window with extra information.
    I have a problem that when I click on checkbox, it count as I changed selection of row too and calls function opening new window.
    How to determine theese two events?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,252
    Thanks
    304
    Thanked 868 Times in 855 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Tree Model with checkboxes click determination

    You can use QModelIndex::data() with the role Qt::CheckStateRole to determine the checked status of the checkbox on the QItemSelection returned by your QItemSelectionModel.

    You might need to keep a separate data structure that keeps track of which items are checked so you can compare the old state and the new state. If the state changes on a click, then you can skip the code that opens the information window.

    By default, any click on any part of a row in a tree view changes the selection, so clicking the checkbox or anything else will cause the QItemSelection to change. The only way you can distinguish between a checkbox click and an actual selection change is with extra code.

    You could also derive a custom QItemSelectionModel and override the QItemSelectionModel::select() slots. In your implementation, you can check the status of the check box and emit a new signal (something like checkStateChanged( const QModelIndex & )) if the state has changed or call QItemSelectionModel::emitSelectionChanged() if it is a row change. Your top level code could then look for the two different signals.
    <=== 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: 0
    Last Post: 2nd September 2020, 23:38
  2. Replies: 1
    Last Post: 19th November 2016, 13:49
  3. SQL Tree Model Help
    By MTK358 in forum Newbie
    Replies: 9
    Last Post: 22nd June 2015, 16:02
  4. Replies: 1
    Last Post: 29th August 2013, 06:41
  5. Checkboxes in QTableView with my custom model
    By frankiefrank in forum Newbie
    Replies: 5
    Last Post: 30th January 2012, 21:08

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.