View Full Version : CheckBox inside a TextEdit

20th August 2011, 21:22
How do I place a Checbox inside a QTextedit? I ask this because I need to create a QTextedit that has a checkbox to print

20th August 2011, 23:43
It is really impossible to think of a checkbox inside a text edit field, in any UI library, in any OS. Checkboxes belong alonside text fields in dialogs, forms, etc.
Your platform seems to be Windows. I don't think you have ever seen a Windows application with a checkbox inside a text field. That ought to give something to think about.

20th August 2011, 23:48
How do I place a Checbox inside a QTextedit?
The same way you place any widget inside any other widget.

21st August 2011, 00:29
Well you could align the checkbox inside the bounds of the edit box...

21st August 2011, 01:40
Is that I want to create a document for QPrintPreviewDialog, that has the checkbox. I want to create a document like the one that is in the Attachments.

And I try HTML:
doc.setHtml( "Soccer: <input type=\"checkbox\" name=\"sports\" value=\"soccer\" /><br />");
but doesnt work.

21st August 2011, 09:14
So you don't want a checkbox inside QTextEdit but rather a checkbox inside a document. You need to subclass QTextObjectInterface and implement a checkbox text object.

21st August 2011, 22:49
What is the checkbox text object? After your reply walked to investigate on google and found this examples:


My doubt is how can I implement checkboxtextobject. In the example of nokia, they use QTextFormat:: UserObject and svgtextobject.cpp they use the drawImage method, as is the draw for the checkbox?

21st August 2011, 23:22
You need to implement a similar text object for the checkbox as they have for svg images.

23rd August 2011, 06:42
I need know how to change cursor for the next 2 line , after the table to put my checkbox. Do you know how?

QTextDocument *document = ui->textEdit->document();
QTextCursor cursor(document);

cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);

QTextCharFormat format;
QTextTableFormat fmtTable;
QFont fonte;
cursor.insertText("1. Identificação\n\n");

QTextTable *table =cursor.insertTable(1,2,fmtTable);
table->cellAt(0, 0).firstCursorPosition().insertText("Nome : ");
table->cellAt(0, 1).firstCursorPosition().insertText("Helder Lobato");

cursor.insertText("\n\n1. Identificação\n\n");

23rd August 2011, 08:32
I don't know what you mean by "change cursor".

23rd August 2011, 14:34
I want to continue writing the text after created the table, the problem is that after you create the table, I can't get out of the table cells.
Look in the atchament.

Ths in advance, Sorry for my English, I'm Portuguese and I am using bing and google to do the translation

23rd August 2011, 17:02
QTextCursor has all the facilities needed to reposition the cursor.

23rd August 2011, 19:32
Thanks, it was very stupid, was so tired during this morning that even noticed I was using the QTextCursor:: End without using the function movePosition.

24th August 2011, 22:40
Good Afternoon,

Wysota, would you could you explain me with an example how can I introduce a checkbox QTextDocument as you can see the attachment that I generated with QPrinter: PdfFormat. What I did to circumvent the problem of the checkbox, was to insert an image checkbox. The problem is that my teacher did not like the solution. Did you could write a mini code, or give me a link where I can draw inspiration?

24th August 2011, 23:09
We are not allowed to give solutions to school assignments, so don't expect complete code from us. The SVG example should give you a good idea what you should do, just instead of drawing images, render a checkbox, either by yourself or using QStyle API.

25th August 2011, 04:08
I 'm not asking you to deliver me to the resolution of my problem, and if you repares in my posts in this forum I never asked such a thing.
I come here only for information about Qt, to understand how to work with him, and learn more about Qt to apply this in my actual ou future works.
Because sometimes you dont understand documentations and you need example ou someone to explain for you undersant.

And I asked you that, a mini-code or a link so I can understand and learn how to do what I want in Qt, because I've been looking on google,
read the documentation and Qt tutorial and I not understand how.

25th August 2011, 08:31
As I said, the example with the SVG item is all you need. I could make another example but it would probably be very similar if not worse than the SVG text item example so it doesn't make much sense, does it? At this point you just have to sit down, analyze, think and experiment.