简体   繁体   中英

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.

在此处输入图片说明

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

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

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.

编辑

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM