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. What does "copy()" do in signal / slot ?

What does "copy()" do in signal / slot ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.1k Views 3 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by aha_1980
    #1

    Here is a simple question .
    Using QtDesigner "Edit signal / sots" drag and drop GUI.

    How do I find out what the actual "pressed" & "copy" do ?
    "pressed" is obvious, but what does "copy " do ?

    What document to read ?

    " 035a0040-123c-4453-a45f-d7fdeacec83d-image.png

    ODБOïO 1 Reply Last reply
    0
    • A Anonymous_Banned275

      Here is a simple question .
      Using QtDesigner "Edit signal / sots" drag and drop GUI.

      How do I find out what the actual "pressed" & "copy" do ?
      "pressed" is obvious, but what does "copy " do ?

      What document to read ?

      " 035a0040-123c-4453-a45f-d7fdeacec83d-image.png

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @AnneRanch hi
      you are connecting "pressed" signal of the button to the "copy" slot of the plainTextEdit

      1 Reply Last reply
      4
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @AnneRanch:

        What document to read ?

        The documentation of the classes you connect.
        In this case, as @LeLev said, you 're connecting a signal of QPushButton, so the docs are here: https://doc.qt.io/qt-5/qpushbutton.html.

        pressed() in particular is an inherited signal, so you can go to the list of all members (including inherited ones) through a link near the top on that doc page and you'll land here: https://doc.qt.io/qt-5/qpushbutton-members.html

        Same with the copy() slot. You go to the related class, QPlainTextEdit in this case: https://doc.qt.io/qt-5/qplaintextedit.html

        Unrelated tip - buttons have a pressed(), released() and clicked() signals. It is most common to connect actions to clicked() signal, which is triggered after a press and following release on the button. You usually don't want to trigger actions directly on press. On most platforms it's uncommon or down right frowned upon. For example it should be possible to press, move the mouse out of the button while holding mouse pressed and then release outside to cancel the action. This is handled by connecting to clicked() signal, which won't be triggered in such case. If you connect to pressed() instead you're executing the action right away. In some scenarios it can also result in focus transfer problems when you're showing dialog windows as the release happens when the focus is already transferred to the new window so it's just safer to avoid that problem and connect to clicked().

        1 Reply Last reply
        3
        • A Offline
          A Offline
          Anonymous_Banned275
          wrote on last edited by
          #4

          Thanks,
          exactly what I was looking for.

          Now for the real
          This is what the doc saiz about this copy function

          Copies any selected text to the clipboard.

          So prior to invoking the "connect" what would be a sample user's way selecting the text so the "connect" will copy it to clipboard ?

          Perhaps not so simple as "highlight status bar text" ?

          Or "selecting text" in code ?

          As far as using "pressed" instead of "click" - no particular reason doing so. Perhaps "faster" response...

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Sorry, I'm not sure I understand the question? Are you asking how to programmatically select and copy some text?

            QPlainTextEdit already implements by default the standard "text field" behavior i.e. it has text selection and copies it to the clipboard (by invoking copy()) when you press a standard copy shortcut of your platform (ctrl+c on Windows/Linux). In addition to that you can connect the copy() slot to any other ui element's signals e.g. a copy action in a menu, on a toolbar or to a button like you have above.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Anonymous_Banned275
              wrote on last edited by
              #6

              @AnneRanch said in What does "copy()" do in singal / slot ?:

              Copies any selected text to the clipboard.

              I am questioning the "selected text" part.
              If I highlight anything in this forum frame , doI perform such selection?
              I am not sure if that works in Qt "text' widget .
              I can add text to "plain text edit " object , but I woudl not call it "selected text". However, can I highlight it by using mouse WITHOUT additional code ?

              If so - then will I have " any selected text" to "copy" to clipboard , per doc?
              I realize this is pretty academical to ask, but cannot come up with better example.

              1 Reply Last reply
              0
              • Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by
                #7

                If I highlight anything in this forum frame , do I perform such selection?

                Yes

                I am not sure if that works in Qt "text' widget .

                Yes, it works exactly like that.

                can I highlight it by using mouse WITHOUT additional code

                Yes, you can highlight it with mouse or keyboard, just like you would in a notepad app, in a browser or any other typical text control. It's built-in. No additional code is needed:

                Example:

                selection

                Just QPlainTextEdit without any additional code. The "selected text" is the part highlighted in blue. Standard copy, paste, cut, select all and even undo actions with their shortcuts work out of the box. There's also a right click menu with all these actions built-in. No additional code.

                1 Reply Last reply
                4

                • Login

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