tsragravorogh
tsragravorogh

Reputation: 3153

Customizing QLineEdit

I have read some posts but none of them apply to what I want to do. I need a QLineEdit that will edit a vector of numbers (let's say a vector of 3 doubles). I want to represent my vector in parenthesis in the QLineEdit and separate the vector elements with a comma. So if the QLineEdit is set to edit a vector of 5 elements, its contents should be like this - (1, 2, 3, 4, 5). The user should be able to edit the numbers, but obviously not be able to touch either the parenthesis or the commas, since they are separators.

What is the best way to achieve this? One thing that's coming to my mind is have as many QLineEdits as there are elements in the vector, but make it appear to the user as if it's one QLineEdit. Insert the commas in between in a QLineEdit control that is read-only. Same can be done with the parenthesis.

Do you think it's the best way or there's a better approach?

Thank you!

Here's a screenshot of what I want it to look like. I want the user to be able to edit the numbers only, but not the commas or the parenthesis.

enter image description here

P.S. I just realized that my offered solution will take a lot of time to implement and it has a lot of edge cases. Because I have to allocate certain space for each QLineEdit and then becomes numbers can be longer they have to be resized, same when the numbers get shorter.

Upvotes: 0

Views: 428

Answers (2)

Thomas
Thomas

Reputation: 5138

There is no ideal solution to this. What I like is a button that brings up an editor. Note the 'greyed out' to indicate that it is not directly editable.

Edit

Here is an example of what an invoked editor could look like. It provides an edit element for each item.

enter image description here

Upvotes: 1

tsragravorogh
tsragravorogh

Reputation: 3153

Was going through the QLineEdit document and saw the inputMask property. It looks like it is exactly what I need:

http://doc.qt.io/qt-5/qlineedit.html#inputMask-prop

Upvotes: 3

Related Questions