Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt equivalent of some MFC CListCtrl functionality

Qt equivalent of some MFC CListCtrl functionality

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 752 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by Perdrix
    #1

    Some code I am attempting to port to Qt uses a customised version of the MFC CListCtrl control.

    The specifics of the extension aren't critical to me but some of the base function is: The CListCtrl has the ability to display a checkbox, a State Icon and a Small or Large Icon in one of the columns (maybe only the first one):

    b61b7f0f-16f7-47d0-8afc-119a8baca1d5-image.png

    From the documentation it seems that the recommendation is to use a QTreeWidget for this type of display control, but I can't see this type of function in QTreeWidget. I suspect setIcon will deal with one of these but the remainder have me puzzled.

    Have I overlooked something while looking at the docs, or is this something that requires a custom widget, and if it is has anyone been there, done that?

    1 Reply Last reply
    0
    • PerdrixP Offline
      PerdrixP Offline
      Perdrix
      wrote on last edited by Perdrix
      #8

      Arrghh I had misunderstood the CListCtrl code in this case! These aren't actually two icons (even though it looks that way). It is one icon with two small images in it! Sorry - for my confusion reading someone else's code.

      And thank you again for your help.

      1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #2

        Hi
        The views can show a checkbox.
        https://forum.qt.io/topic/92530/configuring-checkbox-when-using-qtreewidget
        Also icons. Not sure about the state icon what that represents?

        In any case, if you can what you want directly, you can always use a Delegate which allows for most things
        if hand coded.

        1 Reply Last reply
        4
        • PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by
          #3

          @mrjj

          I think the stateIcon meaning is whatever you choose it to mean

          Thanks for the stuff about the checkBox, I certainly missed that!

          I couldn't find a lot of tutorial stuff about the delegate classes.

          Are you saying that I could add a stateIcon plus setter and getter to QTreeViewWidget and somehow persuade the code to draw the checkBox, standard Icon and state Icon? I looked at the code of qstyleditemdelegate and couldn't get my head round how it drew just the checkBox and standard icon, never mind how I might sub-class it to draw another icon in the first column

          When I looked at TreeView (as I'd prefer to use a separate model) I couldn't even find an Icon attribute! ???? Am I totally in a mess here?

          Thanks
          David

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Hi,

            Since you seem to have 4 different columns, you might not even need a delegate. You can use the DecorationRole for the image part.

            You can check the Star Delegate Example for a complete custom delegate + editor.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • PerdrixP Offline
              PerdrixP Offline
              Perdrix
              wrote on last edited by Perdrix
              #5

              Errm well actually I have a LOT more columns that - the check box, icon and stateIcon are ALL in the first column as these apply to the row not to a cell. AFAICT the Decoration Role applies to an item (cell) rather than a row?

              ab037334-1af2-4c07-b1e7-53f6f971275c-image.png

              David

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #6

                Indeed, the roles apply to each cell.

                So, yes, you'll have to go the delegate route for that column.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • PerdrixP Offline
                  PerdrixP Offline
                  Perdrix
                  wrote on last edited by Perdrix
                  #7

                  Can you clarify the issues I raised about TreeView and icons - I can't see how that works if there's no setIcon method.

                  Is it possible for a column to have more than one role at the same time? I'm beginning to think that I can't have a column that contains an Icon and a checkbox at the same time, never mind an additional icon! Or can I call QStandardItemModel::setItemData multiple times to assign the checkState and two icons to a an item?

                  D.

                  1 Reply Last reply
                  0
                  • PerdrixP Offline
                    PerdrixP Offline
                    Perdrix
                    wrote on last edited by Perdrix
                    #8

                    Arrghh I had misunderstood the CListCtrl code in this case! These aren't actually two icons (even though it looks that way). It is one icon with two small images in it! Sorry - for my confusion reading someone else's code.

                    And thank you again for your help.

                    1 Reply Last reply
                    2
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      Just to note, views may (and will) request data for several different roles for each cell. So in fact yes you can have text and icon at the same time as a custom text and background color. The item delegate has access to all the data that corresponding to the index it will draw for.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved