views:

118

answers:

3

I'm trying to make an UI that contains a list of such items:


User can change the count of the items, so the UI is dynamic.

What are the best components to get user input, like in the picture? Is it multiple QLabels and QLineEdits?
What is the best way to manage them?

+3  A: 

I have done something similar with several QQueue containers full of QLabel and QLineEdit items. Just append and remove items when the user desires more or less. Could combine that with a QGridLayout and put things where you need. Not sure if that's the best way, but works well for me.

http://doc.trolltech.com/4.4/qqueue.html

QQueue<QLineEdit *> linedit;
QGridLayout *gridboxLayout;
gridboxLayout= new QGridLayout();

linedit.enqueue(new QLineEdit ());
gridboxLayout->addWidget(linedit.last(),row,column);
this->setLayout(gridboxLayout);

You are gonna need to add stuff for keeping track of rows, columns and items and such but that is the basic setup. Just keep appending new items to the QQueue and insert into a new row of the gridLayout. You can even reference them by row and delete them later.

The other easy way to do this, which will work with the designer, if you have a reasonable max number of items, is to just build the whole thing and hide the widgets you don't want to see until you need them.

radix07
QQueue ^.^ Fun to say.
Mark
+4  A: 

If the UI contains a lots of these items you could consider using QTableView (or QTableWidget). You could present the static parts "x=", "(2n" and "t)" in static columns or you could create a delegate which would draw the static parts with different color.

The advantage in using the QTableView instead of QLineEdits is that moving with keyboard is easy. By using the cursor keys you can easily move the focus around. The editing experience is the same as in spreadsheet applications like Excel.

Roku
This isn't really what I want, but I will use it as an "emergency" solution. Thanks.
BlaXpirit
+2  A: 

If you have a large number of very similar widgets (like that), I would recommend either investigating one of the model views, or making a custom widget, and letting those widgets handle the editing themselves. Then your main widget can just make a list of custom widgets in a scrolled area, and not worry about keeping track of each value.

Caleb Huitt - cjhuitt