Make QTextEdit resizeable
-
I have a QTextEdit inside of the main window. Now when i move my mouse cursor over the edges of the QTextEdit widget the resize cursors dont appear, and i cant resize it. Does QTextEdit not have a natural window resizing functionality ? How can i get my QTextEdit widget to be resizeable by using the mouse cursor ?
Edit: mousePressEvent() is already overloaded for the move functionality, so we need to use something else for the resize functionality, most likely the frame, if the frame of QTextEdit can be addressed, and has 8 directional emits, just like a normal window would.
-
When you want to make a widget resizable by the user you have to add QSplitter to your layout.
-
-
@Charon117 said in Make QTextEdit resizeable:
Hm ... i dont see a QSplitter in the Qt Designer.
Then look again: https://doc.qt.io/qt-6/designer-layouts.html - it's a layout option.
-
If QTextEdit doesnt have a built in functionality i would rather like to build it in, instead of using a container to do it for QTextEdit.
@Christian-Ehrlicher said in Make QTextEdit resizeable:
@Charon117 said in Make QTextEdit resizeable:
Hm ... i dont see a QSplitter in the Qt Designer.
Then look again: https://doc.qt.io/qt-6/designer-layouts.html - it's a layout option.
Its Qt 6 exclusively ? I still cant find it in my Qt Designer.
-
@Charon117 You need at least two widgets for enabling "split" layout option. See the two disabled icons between "Vertical Layout" and "Form Layout" icons. If you have only one widgets, you can resize it by resizing the main window.
-
@Charon117 said in Make QTextEdit resizeable:
f QTextEdit doesnt have a built in functionality
A widget does not have a user-resize functionality - it's done via the layouts.
-
I have plenty of widgets in the main window, but the splitter option is still greyed out.
Anyway, all of this just seems to be a dead end. Can we simply not build in the resize functionality ? Does QTextEdit have an actual frame, and how can i address it ?
-
I can make the QFrame bigger by setting it to a box and making midLineWidth bigger. But i still dont know (1) how to change the cursor when it hovers over the QFrame and (2) what actually gets triggered when i press on the frame. The frame has to differentiate between all the 8 different directions its pressed on.
-
You have to set the splitter between your left layout (which you not yet have) and the textedit - select both -> right click - it's properly documented: https://doc.qt.io/qt-6/designer-layouts.html#splitter-layouts
-
@Charon117 said in Make QTextEdit resizeable:
Definitely cant resize it as it stands.
Save your ui, compile your program, start it and your can move the splitter.
-
LOL. I can move the space inbetween the splitter, eg. between two widgets. WTF is that. I cant (1) move the splitter, or (2) resize the splitter. The space in the splitter is always getting used up 100% by whatever widgets are in. We are back to step zero again. We have the QTextEdit in a container, great. Now we have to built in the functionality to resize the splitter ?
Not sure if we are on track with this, this definitely doesnt fullfill the software specification. Which is a freely resizeable QTextEdit.
-
Even if we follow Alice into this wonderland, i only see a vertical and horizontal splitter. If we combine them into the weirdest 4 dimensional 2 layer monster, which would give us "almost" an acceptable outcome it doesnt change the fact that the splitter itself is not moveable, or resizeable. Now we could dock the splitter itself to the main window, which would resize it, ... and we end up with a very weird construct, and several weird bugs.
Can i just get a hint on how to address the frame of QTextEdit and how to build in the resize functionality itself ?
-
I mean i am pretty sure i can implement the resize functionality with resize(), i just dont get if user input on the frame is generated, how to create the appropriate cursor, and how to connect the user input on the frame, if any is generated, to the resize functionality.
-
@Charon117 said in Make QTextEdit resizeable:
nd how to build in the resize functionality itself ?
Reimplement mousePress/mouseMove/mouseRelease event if you don't like to use a QSplitter.
Although I don't understand why this textedit should be resizable in your case - why should the textedit not use all the place it can in the first place? the empty space looks pretty awkward -
Question is still very much open to the people actually reading the question, and understanding it as such. Thank you <3.
Thanks to @Christian-Ehrlicher for pointing out that QTextEdit doesnt have a natural resize functionality, as specified in the question.
-
Message to myself:
Resources gathered so far:
https://forum.qt.io/topic/67019/best-practice-resize-widgets-with-mouse
https://stackoverflow.com/questions/26281192/qt-resizing-a-ui-element-with-the-mouse
https://forum.qt.io/topic/66586/make-a-frameless-qwidget-resizable-with-qrubberband
https://wiki.qt.io/Widget-moveable-and-resizeableReflections:
Using QSizeGrip is an easy and dirty solution, but in this case it seems to do the job. Not a good solution if the resizing icon is not desireable to be ontop of the widget.
Widget-moveable-and-resizeable seems to have done some work to make a sort of container for that already, but no time to look into the functionality. It looks promising, depending on the functionality. The QLabels seem to be a bit distracting and maybe unecessary
The most desireable solution would be an invisible container, that allows resizing in 8 directions, and is able to move itself and its content.
QSplitter is not a solution because QSplitter in and of itself is not resizeable, nor moveable. You are basically starting all over again. QSplitter can be a solution if it is embedded in an overall layout, that manages the resizing operation and moving operations. But the underlying form for the desired functionality is freeform, eg. the user defines how the layout looks like. Therefore QSplitter is not a solution.