Unsolved How to make a Find Dialog quickly
-
Thanks for helping me.
I put qDebug as suggested and i finally found and solved the problem.
Now it's working perfectly.but i still have another concern about when you show that Find Dialog.
Actually, i use the below code to show my Find Dialog.
SearchWin->show();
and it's working perfectly, but when you click on the Mainwindow, the dialog goes behind the main window, thing that I don't like !!
I tried to use the below code, it's really open/show that Find Dialog but to find a word, it doesn't work, even if I click on Find button.
fenFindWord *dlg = new fenFindWord(this); dlg.show();
Please what the difference between both methods of showing a Dialog??
I'd like to use the second method as it's still holding the dialog and the main window both together!Please can you help??
-
@freesix said:
Hi
it should be dlg->show();- Please what the difference between both methods of showing a Dialog??
You show only one.
do you mean between using NEW or not?
like
fenFindWord dlg;
dlg.show();
and
fenFindWord *dlg = new fenFindWord(this);
dlg->show();
?
- Please what the difference between both methods of showing a Dialog??
-
Sorry it's my mistake when writing that post.
it's as below in my projectfenFindWord *dlg = new fenFindWord(this); dlg->show();
Please what the difference between both below methods of showing a Dialog??
**Method 1 : ** fenSearch = new fenFindWord(); fenSearch->show();
**Method 2 : ** fenFindWord *dlg = new fenFindWord(this); dlg->show();
My first question is not to know the difference between both methods,
but to make it work like Microsoft Windows Notepad Find button does.
I mean when you want to search for a word in Win Notepad, it still holding the Find Dialog even if you click on the mainwindow, I mean the Find Dialog is still in front.Unfortunately for my Find Dialog, when you click on the Mainwindow, it goes behind.
Please, How to solve this?
-
hi
The difference between the two methods is that the (this) version give the dialog a parent which
is important for clean up and also for what be "over".If "this" in your **Method 2 : **
is mainwindow im not sure why it goes behind main window.you can try with
setWindowFlags( Qt::WindowStaysOnTopHint );
for the dialog.
maybe
setWindowFlags(( Qt::WindowStaysOnTop | Qt::Dialog); -
Why not just use exec() instead of show()?
-
( Why not just use exec() instead of show()? )
Cause I don't want it to be modal.Anyway, I solved the problem !!!
I was confusing between the class name and the object name in my .cpp fileThanks for helping me.
======
I have another concern, please.
I can save text into a txt file using the two below methods and I can open it too,
but I want it to be opened with the format/style I saved it,
I mean if my font had size 16 and font color blue when I saved it, I want that my App be able to open it the way it has been saved.bool fenprinc::saveAs() { QString fileName = QFileDialog::getSaveFileName(this); if (fileName.isEmpty()) return false; return saveFile(fileName); }
bool fenprinc::saveFile(const QString &fileName) { QFile file(fileName); if (!file.open(QFile::WriteOnly | QFile::Text)) { QMessageBox::warning(this, tr("Application"), tr("Cannot write file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return false; } QTextStream out(&file); #ifndef QT_NO_CURSOR QApplication::setOverrideCursor(Qt::WaitCursor); #endif out << ui->textEdit->toPlainText(); #ifndef QT_NO_CURSOR QApplication::restoreOverrideCursor(); #endif setCurrentFile(fileName); return true; }
-
Hi
Not sure if you mean one font + color or many different fonts and colors:1: font+color
You must save the font size and font color in the file also.
You could use a fixed size header line
and store it first in file.
Then when you read it, then remove the header line
set font + color and use rest of the text as text.2: many fonts +color
You throw away the HTML with >toPlainText();
Dont save it without the html as fonts and colors are there. -
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 -