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. Unused blank space in QCompleter's custom delegate
Forum Updated to NodeBB v4.3 + New Features

Unused blank space in QCompleter's custom delegate

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 384 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.
  • A Offline
    A Offline
    aria_oversky
    wrote on last edited by aria_oversky
    #1

    Hello. I tried implementing a custom delegate in a QCompleter, so that I can display rich text using QTextDocument. But every time there's a word wrap, the QCompleter's popup() has that unused blank space as you can see in the screenshot below.

    Here's my custom delegate code:

    https://pastebin.com/ZFb0H79b

    And here's a snippet of my QLineEdit code that creates and setups the QCompleter as well as the delegate:

    https://pastebin.com/Xmp3rk9B

    I suppose my question is: how do I get rid of that blank space and make the popup widget adjust to the contents properly?

    Any help would be appreciated.

    Edit: My code can't be posted because it keeps saying "Post content was flagged as spam by Akismet.com".
    Edit 2: I've posted the code in Pastebin instead.

    1 Reply Last reply
    0
    • A aria_oversky marked this topic as a regular topic on
    • A aria_oversky marked this topic as a question on
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      The spam flagging is weird, but let's set that aside.
      Have you made sure, this behavior is clearly related to your custom delegate?
      If so, please debug the sizeHint() override and see if it actually gets called.
      Just by code reading, I would assume that you need to re-implement updateEditorGeometry() as well. This method doesn't handle rich text by default.

      Software Engineer
      The Qt Company, Oslo

      A 1 Reply Last reply
      0
      • Axel SpoerlA Axel Spoerl

        The spam flagging is weird, but let's set that aside.
        Have you made sure, this behavior is clearly related to your custom delegate?
        If so, please debug the sizeHint() override and see if it actually gets called.
        Just by code reading, I would assume that you need to re-implement updateEditorGeometry() as well. This method doesn't handle rich text by default.

        A Offline
        A Offline
        aria_oversky
        wrote on last edited by
        #3

        @Axel-Spoerl said in Unused blank space in QCompleter's custom delegate:

        Have you made sure, this behavior is clearly related to your custom delegate?
        If so, please debug the sizeHint() override and see if it actually gets called.

        Yes, the base class sizeHint() worked as usual. It's only once I made use of the QTextDocument in the delegate that this problem began occuring.

        I don't know if this will help or not, but here's the calculated QSize (the first QSize is from calling QStyledItemDelegate::sizeHint(), while the second is from calling QTextDocument.size().toSize()):

        QSize(363, 18) QSizeF(246, 36)
        QSize(186, 36) QSizeF(246, 36)
        QSize(48, 18) QSizeF(246, 18)
        QSize(52, 18) QSizeF(246, 18)
        QSize(363, 18) QSizeF(246, 36)
        QSize(363, 18) QSizeF(246, 36)
        QSize(186, 36) QSizeF(246, 36)
        QSize(48, 18) QSizeF(246, 18)
        QSize(52, 18) QSizeF(246, 18)
        QSize(363, 18) QSizeF(246, 36)
        QSize(186, 36) QSizeF(246, 36)
        QSize(48, 18) QSizeF(246, 18)
        QSize(52, 18) QSizeF(246, 18)
        QSize(186, 36) QSizeF(246, 36)
        QSize(48, 18) QSizeF(246, 18)
        QSize(52, 18) QSizeF(246, 18)
        

        "246" is the width of my QLineEdit (and by extension, the QCompleter's popup).

        Just by code reading, I would assume that you need to re-implement updateEditorGeometry() as well. This method doesn't handle rich text by default.

        I'm not sure how overriding that would be the solution here, since I'm not using nor am I ever planning on using any editor widget in my custom delegate.

        But I went ahead and tried reimplementing it anyway like you said, by following this guide, since I was honestly running out of options here. But unfortunately, and as I kinda expected, it still didn't fix my issue.

        1 Reply Last reply
        0
        • Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #4

          The screen shot looks like the height is to big in the first place, but then snaps back to a proper size.
          That's actually not a blank space, but a blank line, right?
          Sometimes a scroll bar appears for a short moment, but it doesn't look like this is the reason for the size mismatch.

          while the second is from calling QTextDocument.size().toSize()

          I don't believe that, because QSizeF::toSize() doesn't return QSizeF, which is the type shown in the debug output.
          But never mind, at least the sizeHint() final override consistently returns the same size.
          That means that the list view gets another (wrong) size before it snaps back.

          You need to figure out where this size information comes from.
          If you are sure somewhere in your code, that QCompleter::popup() will return a valid pointer, you could install an event filter on the returned QAbstractItemView and filter QEvent::Type::Resize, cast the event pointer to a QResizeEvent and check the size. You know the wrong size already, so you could qFatal() when you find it and look a t the stack trace.

          Software Engineer
          The Qt Company, Oslo

          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