Results 1 to 4 of 4

Thread: TreeView, how to status on a row?

  1. #1
    Join Date
    Nov 2020
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Symbian S60

    Default TreeView, how to status on a row?

    I am developing an application in Qt (5.10), Linux. It constists of C++, Qml and JavaScript.

    I have successfully made a tree structure using TreeView which has clickable rows.
    When double clicking on a row, onDoubleClick is handled and a call is made to C++ code to fetch data.
    The data is then inserted into the model and then the row will have a + at the beginning of the row.
    When clicking the + the row is collapsed and data is visible, can be a few lines or more.
    A selected row has by default blue color. The text is black.

    All this works perfect but now I have an intention to show when data could not be read, I want the row to be red to indicate failure. The row should stay red after this.
    Another thing I want to do is to have some kind of indication when fetching data is ongoing, maybe the row could be purple and when finished loading turn to blue again.

    I have tried branchDelegate, rowDelegate, but it seems impossible to make theses changes.

    I would be very happy is someone could give me som piece of advice how to go further.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,236
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: TreeView, how to status on a row?

    Have you implemented the Qt::BackgroundRole and/or Qt::ForegroundRole cases for your model's QAbstractItemModel::data() method to return a QBrush with the appropriate color to indicate the status?
    <=== 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.

  3. #3
    Join Date
    Nov 2020
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Symbian S60

    Default Re: TreeView, how to status on a row?

    Thanks for your response.

    No I have not done such. Are you confident that it should work using these?
    To be hounest, I have no knowledge about how to handle them.

    I want to exaplain a little bit more about my stuff.

    Here are some pseudo lines from my application.

    Qt Code:
    1. TreeView {
    2. id: treeview
    3. anchors.fill: parent
    4. model: treemodel
    5. style: TreeViewStyle {
    6. branchDelegate: Rectangle {
    7. //Only activated when a row is populated with children
    8. width: 15; height: 15
    9. Image {
    10. source: styleData.isExpanded ? "images/minus.svg" : "images/16px/plus.svg"
    11. }
    12. .
    13. .
    14. .
    15. onDoubleClicked: {
    16. //Here is code which calls C++ to get data for children for a specific row (parent)
    17. //If data was found, it is inserted as children into the model
    18. }
    To copy to clipboard, switch view to plain text mode 

    Only when data is inserted as children branchDelegate is activated and the row will have a +.
    When you click on that + it turns to - and children are visible on several rows. Works very well.

    But it seems to be impossible to accomplish what I am looking for:
    At double click, if no data is found mark the row with a different color or similar, maybe a red * instead of - or +.
    In this case branchDelegate is not activated and I am unable to change branch image.

    And the other thing am I looking for a solution to, as earlier written, indicate loading of data, that is for example turn row color to purple during loading.
    Also seems impossible to achieve.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,236
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: TreeView, how to status on a row?

    You said that you wanted the color of the row to indicate the status of that row in some way. It sounds like you have implemented a model for your tree in C++ and you have probably derived it from QAbstractItemModel. When you do that, you have to implement the data() method to return what should be displayed in the tree.

    At a minimum, you have to respond to the Qt::DisplayRole value for the "role" argument to data(). If you look at the documentation for other roles, you will see that there are many of them that you can use to change foreground and background colors, icons, check boxes, fonts, and so forth.

    This has nothing to do with double-clicking. It simply tells the tree view how to display everything about a row's content. So if you want to color-code the rows based on some kind of status, you have to implement either the ForegroundRole or BackgroundRole case for the data() call, and choose the right color to return (as a QBrush) based on the status.
    <=== 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.

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

    virago1100 (23rd November 2020)

Similar Threads

  1. Replies: 3
    Last Post: 8th July 2010, 07:41
  2. Status Bar
    By waynew in forum Newbie
    Replies: 3
    Last Post: 21st November 2009, 09:07
  3. status bar dispaly
    By bhogasena in forum Qt Programming
    Replies: 5
    Last Post: 30th January 2009, 17:27
  4. Status Widget
    By user_mail07 in forum Qt Programming
    Replies: 4
    Last Post: 18th June 2008, 07:51
  5. need help with the status bar
    By filmfreak in forum Qt Programming
    Replies: 2
    Last Post: 15th February 2006, 08:34

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.