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

How to make a label mouse selectable

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

    Hi,

    Is it possible to make a label mouse selectable? In other words what I want is be able to copy the text in a label.

    If yes, can someone be so kind and show me how to do this, I read the QLable class reference but I cannot figure it out.

    Thanks a lot

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      See "setTextInteractionFlags":http://qt-project.org/doc/qt-4.8/qlabel.html#textInteractionFlags-prop, especially Qt::TextSelectableByMouse.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Or, you use a QLineEdit, and set it to read only. If you want, you can also remove the box so it looks like any QLabel.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fs_tigre
          wrote on last edited by
          #4

          It worked.
          ui->label_TotalParts->setTextInteractionFlags(Qt::TextSelectableByMouse);

          bq. Or, you use a QLineEdit, and set it to read only. If you want, you can also remove the box so it looks like any QLabel.

          I tried this but I didn't like the fact that it looked like an input field, since I couldn't removed the box only the outline (border).

          How do you remove the actual box?

          Thank you all for your help

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            You can call:
            @
            theLineEdit->setFrame(false);
            @
            Then, you could also make it disabled. However, that will make the text look greyed out too, so you'd have to eiter set the palette or a style sheet. All in all, I think the QLabel::setTextInteractionFlags() is an easier and better solution.

            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