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
Forum Updated to NodeBB v4.3 + New Features

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.2k Views 2 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.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Qt Champions 2022
    wrote on 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
    • BharathiB Bharathi

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

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on 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
      • BharathiB Offline
        BharathiB Offline
        Bharathi
        wrote on last edited by
        #5

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

        kshegunovK 1 Reply Last reply
        0
        • BharathiB Offline
          BharathiB Offline
          Bharathi
          wrote on last edited by
          #6

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

          1 Reply Last reply
          0
          • BharathiB Bharathi

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

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on 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

            raven-worxR 1 Reply Last reply
            0
            • kshegunovK kshegunov

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

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on 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

              BharathiB 1 Reply Last reply
              1
              • raven-worxR raven-worx

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

                BharathiB Offline
                BharathiB Offline
                Bharathi
                wrote on last edited by
                #9

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

                raven-worxR 1 Reply Last reply
                0
                • BharathiB Bharathi

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

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on 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 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
                    0
                    • S Shrey12

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