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 975 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.
  • coaxmetalC Offline
    coaxmetalC Offline
    coaxmetal
    wrote on last edited by coaxmetal
    #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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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

      coaxmetalC 1 Reply Last reply
      1
      • SGaistS SGaist

        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.

        coaxmetalC Offline
        coaxmetalC Offline
        coaxmetal
        wrote on 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
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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

          coaxmetalC 1 Reply Last reply
          0
          • SGaistS SGaist

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

            coaxmetalC Offline
            coaxmetalC Offline
            coaxmetal
            wrote on last edited by coaxmetal
            #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
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 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

              coaxmetalC 1 Reply Last reply
              1
              • SGaistS SGaist

                The option is initialized in QStyledItemDelegate::initStyleOption.

                coaxmetalC Offline
                coaxmetalC Offline
                coaxmetal
                wrote on last edited by
                #7

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

                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