How to make a label mouse selectable



  • 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


  • Moderators

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



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



  • 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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.