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. How do I initialize QStyleOptionViewItem from an index?
Forum Updated to NodeBB v4.3 + New Features

How do I initialize QStyleOptionViewItem from an index?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 991 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.
  • C Offline
    C Offline
    coaxmetal
    wrote on 6 May 2020, 14:19 last edited by coaxmetal 5 Jun 2020, 14:22
    #1

    So, I have a custom delegate QStyledItemDelegate, whose paint method takes: painter, option and index. I want to generate some scrolling information based on these values, more precisely, using the option and the index. But I want to do it in QListView which uses the delegate and not in the paint method itself. To that end, I need to somehow generate the right option for a given index, just like the one which is passed to the paint method. How can I do that?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 May 2020, 18:22 last edited by
      #2

      Hi,

      Can you explain more precisely what you are trying to achieve ?
      It's not very clear what you want to do within the QListView.

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

      C 1 Reply Last reply 7 May 2020, 10:58
      1
      • S SGaist
        6 May 2020, 18:22

        Hi,

        Can you explain more precisely what you are trying to achieve ?
        It's not very clear what you want to do within the QListView.

        C Offline
        C Offline
        coaxmetal
        wrote on 7 May 2020, 10:58 last edited by
        #3

        @SGaist Bascially, I want to make multiple anchor points (or a scroll grid) for an item, so as to avoid situations when the stuff inside an item is shown only partially (at the top of the widget). To generate the anchor points, I need to know things like option.fontMetrics.

        I figured viewOptions() produces the fontMetrics I need. But option should also contain some index-specific info, right? Not that I can think of a use for that right now, but I am curious if that would be possible to obtain should the need arise.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 7 May 2020, 18:26 last edited by
          #4

          Can you show a picture of what it should look like ?

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

          C 1 Reply Last reply 7 May 2020, 23:07
          0
          • S SGaist
            7 May 2020, 18:26

            Can you show a picture of what it should look like ?

            C Offline
            C Offline
            coaxmetal
            wrote on 7 May 2020, 23:07 last edited by coaxmetal 5 Jul 2020, 23:13
            #5

            @SGaist Sure,

            So, basically, I never want text to be cut like this when scrolling at the top of the widget:

            2020_05_08__04_46_15__820562542.png

            Only this is allowed after a scroll:

            2020_05_08__04_48_10__260020934.png

            or this

            2020_05_08__05_11_36__221145242.png

            Everything is working fine already, it wasn't hard to do. At this point, I am just curious if there's a way to somehow get option so that's it's just the same as passed to QStyledItemDelegate::paint. QListView::viewOptions() is a start, but it doesn't contain any index-specific info. I know I can get option.rect info with QListView::rectForIndex. But I am not sure if rect is all there's to it (I don't know which other fields are index specific). Again, this is for curiousity. AFAIK viewOptions + rectForIndex give me all the info I need for now, but some sort of optionForIndex would just be cleaner and nicer to have.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 8 May 2020, 19:22 last edited by
              #6

              The option is initialized in QStyledItemDelegate::initStyleOption.

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

              C 1 Reply Last reply 9 May 2020, 10:41
              1
              • S SGaist
                8 May 2020, 19:22

                The option is initialized in QStyledItemDelegate::initStyleOption.

                C Offline
                C Offline
                coaxmetal
                wrote on 9 May 2020, 10:41 last edited by
                #7

                @SGaist Great, thanks, that's what I was looking for!

                1 Reply Last reply
                0

                1/7

                6 May 2020, 14:19

                • Login

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