Unused blank space in QCompleter's custom delegate
-
Hello. I tried implementing a custom delegate in a
QCompleter, so that I can display rich text usingQTextDocument. But every time there's a word wrap, theQCompleter'spopup()has that unused blank space as you can see in the screenshot below.
Here's my custom delegate code:
And here's a snippet of my
QLineEditcode that creates and setups theQCompleteras well as the delegate: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. -
A aria_oversky marked this topic as a regular topic on
-
A aria_oversky marked this topic as a question on
-
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 thesizeHint()override and see if it actually gets called.
Just by code reading, I would assume that you need to re-implementupdateEditorGeometry()as well. This method doesn't handle rich text by default. -
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 thesizeHint()override and see if it actually gets called.
Just by code reading, I would assume that you need to re-implementupdateEditorGeometry()as well. This method doesn't handle rich text by default.@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 thesizeHint()override and see if it actually gets called.Yes, the base class
sizeHint()worked as usual. It's only once I made use of theQTextDocumentin 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 callingQTextDocument.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 myQLineEdit(and by extension, theQCompleter'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.
-
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 returnQSizeF, which is the type shown in the debug output.
But never mind, at least thesizeHint()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, thatQCompleter::popup()will return a valid pointer, you could install an event filter on the returnedQAbstractItemViewand filterQEvent::Type::Resize, cast the event pointer to aQResizeEventand check the size. You know the wrong size already, so you couldqFatal()when you find it and look a t the stack trace.