April 12, 2012

fs_tigre fs_tigre
Ant Farmer
146 posts

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

4 replies

April 12, 2012

mlong mlong
Mad Scientist
1517 posts

See setTextInteractionFlags [qt-project.org], especially Qt::TextSelectableByMouse.

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

April 12, 2012

Andre Andre
Area 51 Engineer
6031 posts

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

April 12, 2012

fs_tigre fs_tigre
Ant Farmer
146 posts

It worked.
ui->label_TotalParts->setTextInteractionFlags(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.

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

April 13, 2012

Andre Andre
Area 51 Engineer
6031 posts

You can call:

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

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

 
  ‹‹ OpenSSL and Qt. Need help.      How can we simulate a mousemoveEvent ››

You must log in to post a reply. Not a member yet? Register here!