PDA

View Full Version : CheckBox inside a TextEdit



afro_cv
20th August 2011, 20: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

mvuori
20th August 2011, 22: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.

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

squidge
20th August 2011, 23:29
Well you could align the checkbox inside the bounds of the edit box...

afro_cv
21st August 2011, 00: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.

wysota
21st August 2011, 08: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.

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

http://developer.qt.nokia.com/doc/qt-4.7/qtextformat.html
http://doc.qt.nokia.com/latest/richtext-textobject.html

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?

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

afro_cv
23rd August 2011, 05: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::Start);
cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);

QTextCharFormat format;
QTextTableFormat fmtTable;
fmtTable.setCellSpacing(0);
fmtTable.setBorder(1);
format.setFontWeight(QFont::Bold);
QFont fonte;
fonte.setFamily("Calibri");
fonte.setBold(true);
fonte.setPointSize(12);
cursor.mergeCharFormat(format);
cursor.insertText("1. Identificação\n\n");
format.setFont(fonte);

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");

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

afro_cv
23rd August 2011, 13: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

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

afro_cv
23rd August 2011, 18: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.

afro_cv
24th August 2011, 21: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?
6784

wysota
24th August 2011, 22: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.

afro_cv
25th August 2011, 03: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.

wysota
25th August 2011, 07: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.