How to add QWidget to QTextEdit?
-
I am using class derived from QTextEdit , I can build standard “window” Qt Area window and add Qwidget to it.
BUT I end up with two independent windows .What I need is Qt Area sub-window containing Qwidget .
- What is the standard window area name I want to write the Qwidget "Form" into ?
- I coded QWidget as QTextEdit variable and in constructor and it did not accomplish what I wanted.
-
@AnneRanch
You cannot add aQWidget
to aQTextEdit
. AQTextEdit
contains text, and that's it, no further widgets.What is a "Qt Area window"? If you are still talking about a
QMdiArea
, and you want to be able to place more than one widget on any of theQMdiSubWindow
s, you will want to create the child window as a plainQWidget
and then add subwidgets onto that. The hierarchy will look like:QMdiArea QMdiSubWindow QWidget QVBoxLayout widget1 (e.g. QTextEdit) widget2 (e.g. QLabel) widget3 (e.g. QComboBox) etc.
If your
Form
is aQWidget
and you want that as a subwindow itself then you can use thatForm
as theQWidget
in the above hierarchy.You started out from an example which illustrated MDI windows by using a
QTextEdit
for each subwindow, because it was designed for editing the text of multiple files. It was not a suitable example (in its use ofQTextEdit
s as the subwindows) if not to be used just for that. -
@JonB said in How to add QWidget to QTextEdit?:
@AnneRanch
You cannot add aQWidget
to aQTextEdit
. AQTextEdit
contains text, and that's it, no further widgets.What is a "Qt Area window"? If you are still talking about a
QMdiArea
, and you want to be able to place more than one widget on any of theQMdiSubWindow
s, you will want to create the child window as a plainQWidget
and then add subwidgets onto that. The hierarchy will look like:QMdiArea QMdiSubWindow QWidget QVBoxLayout widget1 (e.g. QTextEdit) widget2 (e.g. QLabel) widget3 (e.g. QComboBox) etc.
If your
Form
is aQWidget
and you want that as a subwindow itself then you can use thatForm
as theQWidget
in the above hierarchy.You started out from an example which illustrated MDI windows by using a
QTextEdit
for each subwindow, because it was designed for editing the text of multiple files. It was not a suitable example (in its use ofQTextEdit
s as the subwindows) if not to be used just for that.Yes, I am back to the MDI window example and YES I want to modify the hierarchy WITHOUT destroying the current child window class.
I'll will use your hierarchy and hope it will work.
I may have said this before - but MDI "example "code flow is not that easy to "decode" .
The authors "code comments" are pretty skimpy...
-
@AnneRanch said in How to add QWidget to QTextEdit?:
YES I want to modify the hierarchy WITHOUT destroying the current child window class.
I know. You can keep the class which is derived from
QTextEdit
if it does something for you. What you cannot do is make that the direct child widget of theQMdiSubWindow
IF you want to put some more widgets on the window. Which I think is what you are wanting to do. If you want multiple widgets on aQMdiSubWindow
, you need to make its child a GenericQWidget
, add a layout to it, and then add whatever widgets you want there (including yourQTextEdit
). But as long as you keep theQLineEdit
as theQMdiSubWindow
's widget you're not set up to then add any further widgets.