Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make a Find Dialog quickly
Qt 6.11 is out! See what's new in the release blog

How to make a Find Dialog quickly

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 4 Posters 7.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mrjjM mrjj

    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.

    F Offline
    F Offline
    freesix
    wrote on last edited by
    #12

    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)??

    PS : Logic will get you from A to B, but Imagination will take you everywhere...

           Albert Einstein
    
    mrjjM 1 Reply Last reply
    0
    • F freesix

      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)??

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #13

      @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()

      1 Reply Last reply
      0
      • F Offline
        F Offline
        freesix
        wrote on last edited by
        #14

        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???

        PS : Logic will get you from A to B, but Imagination will take you everywhere...

               Albert Einstein
        
        mrjjM 1 Reply Last reply
        0
        • F freesix

          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???

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #15

          @freesix

          • 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.

          F 1 Reply Last reply
          0
          • mrjjM mrjj

            @freesix

            • 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.

            F Offline
            F Offline
            freesix
            wrote on last edited by freesix
            #16

            @mrjj

            "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????

            PS : Logic will get you from A to B, but Imagination will take you everywhere...

                   Albert Einstein
            
            mrjjM 1 Reply Last reply
            0
            • F freesix

              @mrjj

              "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????

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #17

              @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.
              F 1 Reply Last reply
              0
              • mrjjM mrjj

                @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.
                F Offline
                F Offline
                freesix
                wrote on last edited by
                #18

                @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.

                PS : Logic will get you from A to B, but Imagination will take you everywhere...

                       Albert Einstein
                
                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #19

                  @freesix said:
                  yes is for whole text. it seems.

                  U need to read into using
                  QTextCharFormat
                  QTextCursor

                  it has been ask many times
                  http://stackoverflow.com/questions/5427572/how-to-change-current-line-format-in-qtextedit-without-selection

                  prepare to spend some time to understand it.

                  1 Reply Last reply
                  1
                  • F Offline
                    F Offline
                    freesix
                    wrote on last edited by freesix
                    #20

                    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;
                    

                    PS : Logic will get you from A to B, but Imagination will take you everywhere...

                           Albert Einstein
                    
                    mrjjM 1 Reply Last reply
                    0
                    • F freesix

                      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;
                      
                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #21

                      @freesix

                      • 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

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved