Solved [PySide6] How to shorten a Qlabel containing text when resizing?
-
I've built an interface where I have a QLabel which contains a list of selected files by the user.
When the user selects some files, I build a string with all the names of the files, then I pass the string to a function to elide it if necessary to prevent the label to resize the main window and then I print the string to the label.
When I drag the right side of the window to widen it, the label resizes accordingly and the text is updated to fit the new width of the label.
The problem comes when I shorten the window, in that case, the label prevents the resizing because of the text I suppose.
In QMainWindow's resizeEvent() I set the label text to an empty string and then I print it back, I thought this could work, but it doesn't, the window shrinks a bit, then it doesn't anymore, I have to stop the dragging and to start it again to be able to shrink a few more pixels and so on.How can I fix this problem?
You can read the full code here:
https://github.com/LuigiCaradonna/isoviewerInvolved code is inside these methods
browseFile(self)
where the text is set for the first timeresizeEvent(self, event)
which should continuously resize the label and elide its content accordinglyelideText(self, label, text)
which generates the elided textIf you want to test it, create some new empty text files with a long name and .PGR extension, then load them using the bottom left button.
-
I've solved setting the Horizontal Policy to "ignore".
-
I've solved setting the Horizontal Policy to "ignore".