Skip to content

Selectable Text #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MistahMojo opened this issue Jun 20, 2020 · 5 comments
Closed

Selectable Text #236

MistahMojo opened this issue Jun 20, 2020 · 5 comments

Comments

@MistahMojo
Copy link
Contributor

MistahMojo commented Jun 20, 2020

Hello, is there a way to make the Text widget selectable by the user?

I can see this in the Qt docs https://doc.qt.io/qt-5/qlabel.html#textInteractionFlags-prop, and this as an enum in the base nodegui https://docs.nodegui.org/docs/api/generated/enums/textinteractionflag, but as far as I can see in the docs there is no way to set this in the react version, as it's not a qproperty or configurable in the props.

Is this a 'missing' feature or do the docs just not cover this?

@a7ul
Copy link
Collaborator

a7ul commented Jun 20, 2020

Hey @MistahMojo
Seems like textInteractionFlag is a property

So, nodegui has a builting method called setProperty that you can use to set it.

In case of nodegui you could do:

import { QMainWindow, QLabel } from '@nodegui/nodegui';

const win = new QMainWindow();
win.resize(500, 500);

const label = new QLabel();
label.setText('Yolo 12321312 313123');
label.setProperty('textInteractionFlags', 1);

win.setCentralWidget(label);
win.show();
(global as any).win = win;

Where value 1 comes from https://doc.qt.io/qt-5/qt.html#TextInteractionFlag-enum

@a7ul
Copy link
Collaborator

a7ul commented Jun 20, 2020

So if you want to do the same in react nodegui.

For now you could just get a ref of the Text instance and ref.current?.setProperty('textInteractionFlags', 1);

@a7ul
Copy link
Collaborator

a7ul commented Jun 20, 2020

Alternatively, if you could help add textInteractionFlags as a prop for Text on react-nodegui library that would be awesome!

@MistahMojo
Copy link
Contributor Author

Thank you, that works!
I'll had a read through the contributing docs. This is a great tool you've got going and if I can help out in any way I'd love to!

@MistahMojo
Copy link
Contributor Author

I've found out this can also be done by adding this style to the element:
qproperty-textInteractionFlags:"TextSelectableByMouse"

Easier than setting a ref and a componentDidMount() to modify it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants