Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Showcase
  4. Rich text delegate
QtWS25 Last Chance

Rich text delegate

Scheduled Pinned Locked Moved Showcase
15 Posts 9 Posters 12.3k 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #1

    The present
    A nice little Qt component I am working on (just needs a bit more spit & polish) is a RichTextDelegate class. It is mend to make Qts item views display and iteraction a bit richer. It is really quite versatile:

    • can render rich text in item cells (doh!)
    • allows display of and interaction with hyperlinks in that rich text (signals provided)
    • wraps the HTML snippets to display in a div that gets some properties set depending on the cell...
    • which can be used to style cells using CSS
    • data roles and flags can be made available as div classes or other attributes, and thus be used in the style sheet itself
    • the same goes for the selected and current status.

    This is already quite versatile. It makes it much easier to separate data contents from presentation already. Things like making a column right-aligned become a trivial two-liner, instead of needing to create a subclass of QAbstractItemModel or one of its subclasses, an proxy model or an item delegate. The idea is to make simple things simple, and the complex ones possible. To make a single column right aligned, would take no more than this:

    @RichTextDelegate* rtd = new RichTextDelegate(m_view);
    m_view->setItemDelegate(rtd);
    rtd->addStyleSheet(".cell.column_2 {text-align:right;}");
    @

    Working with hyperlinks, while not a total replacement of having actual widgets, already allows for quite a bit of useful interaction with items. The rendering of the items contents is done using QtWebkit.

    A version with all the above will be released soon, though the source code is already online for those interested.

    The future
    However, I have more plans for the above to make it even more versatile...
    An extension I am planning, is a way to keep track of data on the model from outside the model itself. This is very much like the current selection model, that keeps track of which items are selected. There will be some basic models like this provided, and a way to easily add new ones. Possibly, these will be proxy models, but the details on their design are not complete yet. The idea is that you can use these extensions to manipulate the presentation if the items using... CSS again as well as store and retrieve this additional information from inside your program. This makes it easy to enrich data from models that you don't have influence on, like the SQL models or the file system model.

    Concrete implementations that I am planning are:

    • a model to store a simple boolean value for a model index
    • a model that can evaluate data and assign states based on it through a simple script. This should allow to set easy rules for presentation of data, such as present negative values in red and positive values in black. Again: the model would provide a flag, that you can use through CSS to come to an actual representation.
    1 Reply Last reply
    0
    • J Offline
      J Offline
      jorj
      wrote on last edited by
      #2

      Looks interesting, I haven't had enough time to play with the Qt Model - View tools yet... Haven't had much use for it in my own code... But after looking through all the old Dev Days Talks and this too... I will have to have a play!

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Gaston
        wrote on last edited by
        #3

        Yeah, looks really interesting. Maybe you could add some screenshots and examples on what it can be done and how it looks.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Thans for the interest.

          I will add some screenshots soon.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            noah
            wrote on last edited by
            #5

            Looks lovely. Any plans on releasing it? I have a few spots where it'd be really handy.

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nomorespam
              wrote on last edited by
              #6

              [quote author="Andre" date="1277118303"]The present

              A version with all the above will be released soon, though the source code is already online for those interested.
              [/quote]

              This looks very interesting. You write, that the source code is available online. Where can I find it? Which license do you use for it?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                I got sidetracked a bit. I'll try to pick this up again. Part of this work can however probably be considdered obsolete, because some of these stylings are easier and better done using a QML view. However, not every view can easily be replaced by a QML view yet (especially table-type and tree-type views still present challenges), so I guess there is still a market for this.

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  nomorespam
                  wrote on last edited by
                  #8

                  Yes, I have a rather complex treeview that needs some richtext love :-)
                  It would be great to take a look at your code for this.

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    cyberbobs
                    wrote on last edited by
                    #9

                    Is it possible to look at your component source code somewhere? I'm going to implement something same to this (though i really need a little subclass of the features you mentioned here) and looking for the already existing implementations.

                    1 Reply Last reply
                    0
                    • U Offline
                      U Offline
                      Uwe Kindler
                      wrote on last edited by
                      #10

                      Hi Andre,

                      I downloaded and tested your RichTextDelegate and your StyleSheetDelegate and they are both great. Exactly the thing I was looking for. Really great!!!. I think they are almost essential for Qt to make use of model / view framework easier. Would be really great to see such stuff in Qt or at least Qxt.

                      Thank you.

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        crociv
                        wrote on last edited by
                        #11

                        Hi Andre,
                        Can I download it to? I'm looking for a good example of solving such a problem

                        1 Reply Last reply
                        0
                        • U Offline
                          U Offline
                          Uwe Kindler
                          wrote on last edited by
                          #12

                          Hi crociv,

                          the code is part of the SAINT toolkit. You will find the code here:

                          "https://www.assembla.com/code/srtools/git/nodes/richtextdelegate_rework/common":https://www.assembla.com/code/srtools/git/nodes/richtextdelegate_rework/common

                          Search for styleheetdelegate and richtextdelegate. But these delegates are not made for large sets of data because they consume a lot of memory and they are slow.

                          1 Reply Last reply
                          0
                          • C Offline
                            C Offline
                            crociv
                            wrote on last edited by
                            #13

                            Uwe Kindler, Thanks!

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              andre
                              wrote on last edited by
                              #14

                              Glad you found it, I hope you'll find it useful.

                              1 Reply Last reply
                              0
                              • H Offline
                                H Offline
                                hisoft
                                wrote on last edited by
                                #15

                                Hi,

                                I downloaded the two files richtextdelegate.cpp / .h, put them into a simple qt project, activate the webkit module (qt += webkit) and got error when compiling :
                                undefined reference to `QWebPage::setViewportSize(QSize const&) const'.

                                Any idea ?

                                Thanks.

                                1 Reply Last reply
                                0

                                • Login

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