Unsolved How to make a Find Dialog quickly
-
Thanks for helping me.
I need it to be like Windows Note Pad.
I mean for example :
I have two lines on my QTextEdit.
on my first line I set the font "Verdana" + the font color "Blue"
and my second line, I set the font "Arial Black" + the font color "Red".
That's what I need.
I think that's what you call "many fonts +color"??You throw away the HTML with >toPlainText(); Dont save it without the html as fonts and colors are there.
I dont think I get you !!!
How not to save it without the html??? (How to do that)??
-
@freesix
Hi, u are welcome.
yes that would be case 2 where u have formatting in whole file.
call toHtml() instead.
U will save all html which includes any font or color change.
Should be exactly the same you load it again and call
setHtml() -
Thanks a lot.
I can now do that.but I still have another concern that is :
When I change the font or color font of my selected text,
it applies that font and color font to the all text in the QTextEdit.
I wanted to only be applied on the selected text.I don't know : I use "QSettings" to save and restore my application settings.
Can I take it out??? -
-
it applies that font and color font to the all text in the QTextEdit.
But does your code try to set it only on the selected text? -
"QSettings" to save and restore my application settings. Can I take it out???
yes ? that is normally to save window position and other setting using this class.
If you dont need it, you can remove it.
-
-
"But does your code try to set it only on the selected text?"
I don't know !!!
I thought as we use QTextEdit combined with .toHTML, it'll do that automatically !!!Please Sir, How to do that???
About "QSetting", when I was using 'toPlainText',
I mean before I hear about that 'toHTML', I was using QSetting to save and restore the font and color font of the QTextEdit Text. It was also working great !!!
Now we use "toHTML" like you said I can remove it.and I also noticed something in the txt file I saved using "toHTML".
when I try to read/open it using Win NotePad, I see HTML formatting. Why???? -
@freesix said:
- "But does your code try to set it only on the selected text?" - I don't know !!!
- I thought as we use QTextEdit combined with .toHTML, it'll do that automatically !!!
hmm. not sure i understand here.
How do you color the selected text?- when I try to read/open it using Win NotePad, I see HTML formatting. Why????
because the fonts and the text is only possible as HTML.
You can not have different color or font size pr line in a true text file.
-
@mrjj
"How do you color the selected text?"
Once I run my App, I select it using my mouse and I click on "Color" or "Font" button that possess the below method.void MainWindow::color() { bool ok = true; QColor couleur = QColorDialog::getColor(Qt::white, this); if (couleur.isValid()) { QPalette palette; palette.setColor(QPalette::Text, couleur); if (ok) { textEdit->setPalette(palette); } } }
Below is for setting a font on a text :
void MainWindow::font() { bool ok = false; QFont police = QFontDialog::getFont(&ok, textEdit->font(), this, "Choisissez une police"); if (ok) { textEdit->setFont(police); } }
but unfortunately it applies it on the all QTextEdit txt.
-
@freesix said:
yes is for whole text. it seems.U need to read into using
QTextCharFormat
QTextCursorit has been ask many times
http://stackoverflow.com/questions/5427572/how-to-change-current-line-format-in-qtextedit-without-selectionprepare to spend some time to understand it.
-
Thanks. will do.
why when I try to read/open the txt file I previously saved using "toHTML" I see HTML formatting inside that txt.
Is there anyway to bypass it, and make it normally like Win Notepad??
==
Can you please explain properly/clearly the below code?
I know it's a condition similar to "If...else" but I really don't know exactly how/when/where to use it.I like that way of doing Qt Conditions. it's really impressive!!!
I just copied it from a book and started using it on my App.
Qt::CaseSensitivity cs = ui->caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
-
-
Is there anyway to bypass it, and make it normally like Win Notepad??
Not really - since you need the HTML format to do colors and fonts inside the text.
If plaintext, its not possible to change font or colors inside the text, ONLY for all of the text. -
Can you please explain properly/clearly the below code?
Its actually pure c++- can be used with non Qt too
Its called a Ternary operator
http://www.cprogramming.com/reference/operators/ternary-operator.html
Qt::CaseSensitivity cs = ui->caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
it says
let cs be set to "Qt::CaseSensitive" OR "Qt::CaseInsensitive" depending on the value of "ui->caseCheckBox->isChecked()"its just another form of if as you say and you can use when ever you you would make a "if then else"
The format is
value = (condition) ? if condition true : if condition false -