PDA

View Full Version : Put QWidget in a QTextEdit



Darktib
13th September 2009, 13:44
Hello,


I have a QTextEdit in which I want to put some QWidgets (for example, buttons, combo box, tab widget, etc...). My idea was to reimplement QTextCursor, QTextEdit, QTextDocument and QTextFrame in order to use a 'QTextWidget' class (derived from QTextFrame I have to create for this to work), or something like that; this class QTextWidget would simply be a container which can return a html string to describe the contained widget (string choosen by the programmer), so this class could be used in conjonction with a modified QTextCursor. But it appears to be very heavy...

Have you other ideas ?

In the case this idea is not bad, I have several questions :
-which methods I should reimplement in QTextCursor and QTextDocument for this to work?
-how to draw widgets when they're in a QTextWidget ? I've seen no drawing methods in QTextObject...

Thank you in advance,

Dartib

Darktib
15th September 2009, 19:30
No idea(s) or comments ?

aamer4yu
16th September 2009, 06:08
My idea was to reimplement QTextCursor, QTextEdit, QTextDocument and QTextFrame in order to use a 'QTextWidget' class (derived from QTextFrame I have to create for this to work), or something like that; this class QTextWidget would simply be a container which can return a html string to describe the contained widget
Isnt this what Qt Designer does ? Not exactly, but seems similiar..
Whats your goal ? You can have a look at graphics view as well...

faldzip
16th September 2009, 11:56
You could try combining Qt::WA_DontShowOnScreen with QWidget::render(). First one is a flag that makes your widget invisible, but with 'visible' porperty set to true - so you get all Paint events and so on. Now catch Paint events with some event filter or something and render your widget to pixmap, which you can place in QTextEdit. In this solution, every Paint event will fire QWidget::render() to render the actual widget state on the pixmap - just refresh it every time and you will have even blinking vista progressbar :]. Worse thing is with event handling - you have to catch for example mouse moves and clicks on you displayed pixmap and send them to the right part of your invisible widget.

P.S. Try giving names to your classes diffrent than "Q..." as it can lead to some misunderstandings, and read your Qt license to see if it is allowed - i dont know, but check just in case

Darktib
16th September 2009, 20:48
Thank you for your answers.

My goal is to have n frames in the text, each contain a widget and can be handled by the user exactly like normal frames.

Using a pixmap seems complicated, and with this I have widget in the QTextEdit, not in the text...