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. Prevent QPlainTextEdit from copying HTML to clipboard?
Forum Updated to NodeBB v4.3 + New Features

Prevent QPlainTextEdit from copying HTML to clipboard?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.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.
  • G Offline
    G Offline
    gkroeger
    wrote on last edited by
    #1

    I need to copy columnar data from a QPlainTextEdit to the clipboard. Since this data will be pasted into spreadsheet programs like Microsoft Excel, I would like to prevent an HTML version going to the clipboard, only plain text. Is there any way to do that? Am I not using the right widget?

    Thanks for any suggestions
    Glenn

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Saugglocke
      wrote on last edited by
      #2

      I would subclass the QPlainTextEdit and override its copy method by formatting the selected text accordingly and then copy it to the clipboard with QApplication::clipboard()->setText(). Also have a look at QClipboard.

      bb

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gkroeger
        wrote on last edited by
        #3

        Thanks bb.

        I have subclasses QPlainTextEdit and overridden copy(). Had to replace unicode paragraph separators with newlines.

        My only issue now is that apparently the key board shortcut for copy (cntrl-C or command-C) doesn't actually call the copy() method.

        Any clues on an easy way to intercept/override that one key stroke?

        Glenn

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rahul Das
          wrote on last edited by
          #4

          RELATED : http://qt-project.org/forums/viewthread/34080/


          Declaration of (Platform) independence.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Saugglocke
            wrote on last edited by
            #5

            Could you provide a small example and how you implemented the copy method?

            Edit: Just tried to do it on my own. Sry, forgot to mention, in order to use your new method you also have to implement the keyPressEvent, something like this:
            @void CLASS::keyPressEvent(QKeyEvent *e)
            {
            if (e->matches(QKeySequence::Copy))
            copy();
            else
            QPlainTextEdit::keyPressEvent(e);
            }@

            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