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. Customizing MVC's view: is it possible to use CSS instead of delegate?
Forum Updated to NodeBB v4.3 + New Features

Customizing MVC's view: is it possible to use CSS instead of delegate?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 708 Views 1 Watching
  • 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.
  • D Offline
    D Offline
    deleted475
    wrote on 25 Mar 2022, 17:21 last edited by deleted475
    #1

    I have a custom widget that serves as a container for labels. Both it's style and labels' style I set with CSS.

    793c6c9c-81f7-452a-97ba-c1d20baab10f-image.png

    But now that I'm switching to MVC model, it looks like this:

    d668db5a-36d8-4871-a2ff-df874d22093a-image.png

    Is it possible to reuse the already existing CSS configuration file and not set custom styled delegate?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 Mar 2022, 19:39 last edited by
      #2

      Hi,

      Did you try to customize your list view ?

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

      D 1 Reply Last reply 25 Mar 2022, 21:09
      0
      • S SGaist
        25 Mar 2022, 19:39

        Hi,

        Did you try to customize your list view ?

        D Offline
        D Offline
        deleted475
        wrote on 25 Mar 2022, 21:09 last edited by
        #3

        @SGaist Thanks! For some reason I didn't see QListView in the list of widgets customizable by CSS.

        One question: is it possible to extract the size of a specific element? Because every time I add a string to the list, I need to enlarge the height of the view by the height of the element

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 26 Mar 2022, 20:41 last edited by
          #4

          Do you mean you want your view to be of the size of the number of element it contains ?

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

          D 1 Reply Last reply 28 Mar 2022, 13:50
          0
          • S SGaist
            26 Mar 2022, 20:41

            Do you mean you want your view to be of the size of the number of element it contains ?

            D Offline
            D Offline
            deleted475
            wrote on 28 Mar 2022, 13:50 last edited by deleted475
            #5

            @SGaist Yes. I'm trying to create a Telegram-like dropdown, if you know what I mean.

            07a1d4cd-4d0d-4bf2-af03-181ebc6fb6f4-image.png

            This dropdown can be enlarged in height up to some maximum value, - then a scrollbar appears. Therefore, to begin with, I need to know the height of an element, so I can manually enlarge the dropdown. For example:

            // Not a real code!
            int newHeight = view->height() + view->elementSize().height();
            view->resize(view->width(), newHeight);
            
            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 28 Mar 2022, 18:24 last edited by
              #6

              Would it be simpler to use a QComboBox ?

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

              D 1 Reply Last reply 28 Mar 2022, 18:51
              0
              • S SGaist
                28 Mar 2022, 18:24

                Would it be simpler to use a QComboBox ?

                D Offline
                D Offline
                deleted475
                wrote on 28 Mar 2022, 18:51 last edited by deleted475
                #7

                @SGaist For the current stage - yes. But in the future this popup will be extended so that each item will have an avatar, last login time, etc. along with the text.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 28 Mar 2022, 19:03 last edited by
                  #8

                  In that case you will need a QStyledItemDelegate.

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

                  D 1 Reply Last reply 28 Mar 2022, 19:14
                  1
                  • S SGaist
                    28 Mar 2022, 19:03

                    In that case you will need a QStyledItemDelegate.

                    D Offline
                    D Offline
                    deleted475
                    wrote on 28 Mar 2022, 19:14 last edited by
                    #9

                    @SGaist Thanks! Last question - as far as I know, delegate is used to draw each item individually. But, returning to the dropdown example, it would be logical to set its model in form of
                    Avatar File Name | Username | Last Login
                    Is it possible to still use list-like view and draw a visual element composed of these three features?

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 28 Mar 2022, 19:21 last edited by
                      #10

                      Each item does not mean you cannot use data from different parts of the model.

                      The model that feeds your list view will likely be a table, so in your delegate you will retrieve the data from the siblings of the current index to do your painting.

                      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

                      1/10

                      25 Mar 2022, 17:21

                      • Login

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