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. Copy formatted text from line edit and paste in another line edit with same format

Copy formatted text from line edit and paste in another line edit with same format

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 7 Posters 3.1k Views
  • 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.
  • B Offline
    B Offline
    Bharathi
    wrote on 15 Jul 2016, 07:21 last edited by
    #1

    How to copy the formatted text from a line edit and paste the text with format in another line edit?
    I try with following code.I can able to paste the text but not with format which I apply in the first line edit.
    @
    secondlineedit->insert(firstlineedit->text());
    @

    K 1 Reply Last reply 15 Jul 2016, 07:44
    0
    • N Offline
      N Offline
      NickV
      wrote on 15 Jul 2016, 07:31 last edited by
      #2

      You can try to do this:

      secondlineedit->setText(firstlineedit->text());

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dheerendra
        Qt Champions 2022
        wrote on 15 Jul 2016, 07:32 last edited by
        #3

        You can try with copy() and paste().. methods provided by the lineEdit.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        3
        • B Bharathi
          15 Jul 2016, 07:21

          How to copy the formatted text from a line edit and paste the text with format in another line edit?
          I try with following code.I can able to paste the text but not with format which I apply in the first line edit.
          @
          secondlineedit->insert(firstlineedit->text());
          @

          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 15 Jul 2016, 07:44 last edited by
          #4

          @Bharathi
          Hi,
          Try this one:

          secondlineedit->setHtml(firstlineedit->toHtml());
          

          Kind regards.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          1
          • B Offline
            B Offline
            Bharathi
            wrote on 15 Jul 2016, 09:49 last edited by
            #5

            @kshegunov
            setHtml is the member for textedit not for line edit.

            K 1 Reply Last reply 15 Jul 2016, 12:35
            0
            • B Offline
              B Offline
              Bharathi
              wrote on 15 Jul 2016, 09:49 last edited by
              #6

              @NickV
              I also try with setText it only copy the text not format

              1 Reply Last reply
              0
              • B Bharathi
                15 Jul 2016, 09:49

                @kshegunov
                setHtml is the member for textedit not for line edit.

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 15 Jul 2016, 12:35 last edited by kshegunov
                #7

                @Bharathi
                Sorry, my bad. But isn't QLineEdit for plain text? How do you have a formatted text in it?

                Read and abide by the Qt Code of Conduct

                R 1 Reply Last reply 15 Jul 2016, 12:54
                0
                • K kshegunov
                  15 Jul 2016, 12:35

                  @Bharathi
                  Sorry, my bad. But isn't QLineEdit for plain text? How do you have a formatted text in it?

                  R Offline
                  R Offline
                  raven-worx
                  Moderators
                  wrote on 15 Jul 2016, 12:54 last edited by
                  #8

                  @Bharathi
                  @kshegunov said:

                  How do you have a formatted text in it?

                  I am also curious about this. QLineEdit doesn't support rich-text/HTML-subset.
                  So about what formatting do you talk?

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  B 1 Reply Last reply 15 Jul 2016, 13:35
                  1
                  • R raven-worx
                    15 Jul 2016, 12:54

                    @Bharathi
                    @kshegunov said:

                    How do you have a formatted text in it?

                    I am also curious about this. QLineEdit doesn't support rich-text/HTML-subset.
                    So about what formatting do you talk?

                    B Offline
                    B Offline
                    Bharathi
                    wrote on 15 Jul 2016, 13:35 last edited by
                    #9

                    @raven-worx
                    intially I give text color in first line using setstylesheet as following code.
                    @
                    firstlinedit->setStyleSheet("color:red;");

                    R 1 Reply Last reply 15 Jul 2016, 13:44
                    0
                    • B Bharathi
                      15 Jul 2016, 13:35

                      @raven-worx
                      intially I give text color in first line using setstylesheet as following code.
                      @
                      firstlinedit->setStyleSheet("color:red;");

                      R Offline
                      R Offline
                      raven-worx
                      Moderators
                      wrote on 15 Jul 2016, 13:44 last edited by
                      #10

                      @Bharathi
                      ok, you can't transfer this kind of formatting.
                      Since it's not part of the content itself, but only used for displaying by the widget (QLineEdit)

                      QLineEdit's public API only support plain text. But internally it actually would support QTextFormats, etc.

                      Probably it's best if you create your custom widget (based on QTextEdit). Make sure to remove the scrollbar policies, filter the ENTER/RETURN key events and override the sizeHint to make it look like a one-liner text entry like the QLineEdit is.

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      3
                      • S Offline
                        S Offline
                        Shrey12
                        wrote on 14 Mar 2019, 16:39 last edited by Shrey12
                        #11

                        I know the question is old. But I came across the same issue today. ( I'm using pyqt5 so my code will be in python.)
                        I solved it using the following logic:
                        for e.g. I have 2 qlineedits named lineedit1 and lineedit2 :
                        To keep the format same, in my case integers, I used setValidator

                        lineedit1.setValidator(QIntValidator())
                        lineedit2 .setValidator(QIntValidator())

                        so to copy contents from lineedit1 to lineedit2, I used the following code:

                        linededit1.textChanged.connect(self.lineedit2.setText)

                        mrjjM 1 Reply Last reply 14 Mar 2019, 16:50
                        0
                        • S Shrey12
                          14 Mar 2019, 16:39

                          I know the question is old. But I came across the same issue today. ( I'm using pyqt5 so my code will be in python.)
                          I solved it using the following logic:
                          for e.g. I have 2 qlineedits named lineedit1 and lineedit2 :
                          To keep the format same, in my case integers, I used setValidator

                          lineedit1.setValidator(QIntValidator())
                          lineedit2 .setValidator(QIntValidator())

                          so to copy contents from lineedit1 to lineedit2, I used the following code:

                          linededit1.textChanged.connect(self.lineedit2.setText)

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 14 Mar 2019, 16:50 last edited by
                          #12

                          @Shrey12
                          Hi and welcome to the forums.
                          Thank you for the input, however, it turned out that Poster wanted to copy a stylesheet
                          between LineEdits which is possible with any of the LineEdits functions.
                          So while your solution will copy the text in an elegant way, its
                          not really the original issues. :)

                          1 Reply Last reply
                          0

                          • Login

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