RichEditCtrl and its text content - c++

I copy all formatted rich edit text into clipboard as
m_edit.setsel(0,-1);
m_edit.copy();
But when I call GetClipboardData,
I obtain text without format.
Someone could explain to me something about this ?

I think you are mistaken. The copy method sends a WM_COPY message to the control. This will place formatted text as well as plain text on the clipboard. Look through all the formats on the clipboard and you will find RTF is present.

Related

QT label setText() while preserving text formatting

I have designed a label in QT Designer and need to set the text from the cpp implementation. This works. But, the text formmatting (size and bold) is being removed.
How can I set the text while preserving the formatting done in the ui file?
Sample:
ui->label_version->setText(QString::fromStdString("1.0.0"));
You can open your ui file with text editor to check what test is set. In real Qt uses HTML to format text. Also, you can set stylesheet.
To save formatting you can try this:
1. Set text "%1" in ui
2. Save text before the change
3. Use saved text + .arg to set new text
Constructor()
{
this->m_savedText = m_ui->myLabel->text();
m_ui->myLabel->setText(this->m_savedText.arg("Default text"));
}
handler()
{
m_ui->myLabel->setText(this->m_savedText.arg("New text"));
}
I found the real issue. I had set the text formatting within the rich text editor. What I needed to do was to set the formatting for the label withing the QtWidget properties. When this was changed all was preserved when setting a new text.
The solution that worked for me is to set at the beginning (designer or with code) textFormat as PlainText, with that, whenever you setText, it keeps the format.

what is the actual meaning of parsing a html file?

I am not able to understand what actually parsing the html means ?
As i understand -
- it means that suppose we have any html file by parsing we can have the contents of the html file and we can edit them using parsing. Am i right ?? (parsing simply gives the idea about the contents and structure inside the file.)
I have one more question-
- I also want to know that suppose i have html file contents stored in a stream suppose (inside IStream *HTMLContents - No matter for now that how i got these contents). Is there any process exist that using these file contents may i create the preview on any window/Dialog Box/Preview pane with the same way exactly as i get the view of that html file in the browser.(for now you can imagine that i have downloded the HTML File contents from any web page(or from any where-No matter- But i have contents of html file in my stream i am sure about it) and i want to render that html file view in my own created window/Dialog Box/Preview pane(i mean it should view exactly as it appears in browser-Yes i know it won't be avle to display some pictures in html file but thats not a problem for me). How to do that ?? (I am using Visual c++ for my accomplishing my task)
Parsing basically means analyzing any data. When you parse HTML, it could be that you are figuring out where all the various elements are located and what do they do.
As for displaying HTML, it depends on what do you want to do:
If you want to open the file in your browser, use something like this.
As for displaying HTML directly in your form, I don't really know of any other way than parsing the HTML and creating your own web rendering engine. Good luck and have fun with that I guess.
Parse HTML means build object model such as DOM: https://en.wikipedia.org/wiki/Document_Object_Model in your program

Saving and loading text files that aren't plain text

So, I'm making a text editor in Qt. And It does mostly very basic functions. New file, save, open, cut, copy, paste, bold, underline, italic, undo, and redo. But, when I bold, italicize, or underline text and then open the text file again It opens as plain text. As in if you open a file, bold some text, save it and then open it again it will be in plain text not bolded or anything. I have tried reading about how to make it work the way I want, but with no luck. My program can even create/open rich text files, but it works the exact same way. I understand that the way I have written the code makes it work the way it does. I just don't know how to "fix" it.
Here are the blocks of code I have written that save and open files using the QFileDialog:
void WordWriteMain::on_actionOpen_File_triggered()
{
QString fileName = QFileDialog::getOpenFileName(this,"Open a file","","Text (*.txt);;Rich Text (*.rtf)");
QFile file(fileName);
if(file.open(QIODevice::ReadOnly|QIODevice::Text)){
ui->textBox->setText((file.readAll()));
}
}
void WordWriteMain::on_actionSave_triggered()
{
QString fileName = QFileDialog::getSaveFileName(this,"Open a file","","Text (*.txt);;Rich Text (*.rtf)");
QFile file(fileName);
if(file.open(QIODevice::WriteOnly|QIODevice::Text)){
file.write(ui->textBox->toPlainText().toUtf8());
}
}
Is what I'm trying to do even possible using QFileDialog? And like I said I understand the line file.write(ui->textBox->toPlainText().Utf8()); converts all of the text into plain text, but I don't know how to make the save slot work without doing it that way.
As always thank you so much for dedicating your time to help me and for reading my question. If there is any more information needed I would be more than happy to provide it. EDIT: Also, I would like in the future to be able to add paragraph aligning so should I make my text editor strictly rich text?
Use toHtml() instead of toPlainText().
When setting use setHtml() instead setText()
Also use toAscii() instead of toUtf8() to do not loose user's language code page.
See: http://doc.qt.io/archives/qt-4.7/qtextedit.html

Picture from dc to Word document

I want to add a picture to my opened word file. But not from file. I have some picture on a DC in my program and want it directly to Word document. Does anybody know how?
At least may be some documents to read advises.
Thanks in advance!
I assume you are able to get an IDispatch pointer to the Word document you plan on inserting the picture on...
Once you have that, you can select the Range you want... Once you have a Range the basic code in VB (which you can translate into C++) is:
Range.InlineShapes.AddPicture("yourfile.png")
Yes, I know you said you didn't have a file or didn't want to use one, but I recommend you create a temporary file, insert it into Word, and then delete it when you're done.
Use the CxImage library on codeproject.com to save your image to disk--assuming you know how to get a HBITMAP or CBitmap of the image you want to save/put into Word.

Builder c++ Rave Reports encoding problem with cyrillic

When i try save rave project in pdf\html file, have incorrect encoding.
When choose format and press SAVE, it ussually save in iso-8859-1 code.
But i need cp1251 (cyrillic).
For example "Ïëîùàäü" instead of "Площадь".
I would guess that the best solution to your problem would be to use Unicode, rather than a codepage such as CP1251. Is it possible to use Unicode with Rave Reports?
I have the same problem when I want o save reprt to pdf format. I have to create TRvRenderPDF and set it as RenderObject but pdf file was viewed not correctrly.
The TRvRenderPDF component not unicode-compatible(that is very bad) that is why all text in report coverted into Ansi with active codepage(for cyrillic it is CP1251). Now we have pdf file with text in CP1251 encoding.
As default TRvRenderPDF generate pdf with font TYPE1 Helvetica(by the standart of the format pdf it is build-in). But text is interpreted with encoding ISO 8859-1(or CP1252) but it encoding was CP1251 tha is why we have "Ïëîùàäü" or something analogous.
What we can to do:
Get font TYPE1(CP1252) where service symbols(numbers like in cyrillic letters in CP1251) replaced with cyrillic glyphs. For example a link and we need to install it.
Now we need tor replace old font name(Helvetica) from generated pdf document with new font name(AGHelvetica). You can dow it with text editor or i your's programm(read file -> find -> replace -> save file).
That all situation.
P.S. Sorry for my english.
P.P.S. If set property of pdf render EmbedBaseFonts = true, pdf document were saved with TrueType fonts, but problem stay. Neew to see to unicode render? but not this one.