tags:

views:

65

answers:

3

http://img804.imageshack.us/img804/4258/uisketch.png

Hello, I am trying to a make a UI, like in the sketch picture (spam prevention made me to post only the link). What should be the boxes type? QListView (boxes should be scrollable)? I have tried that, but I couldn`t manage to add any action to "available actions". I have tried to play with QAction, but nothing seems to work. Actually, actions do not need to do anything, as the selected and moved to other box action numbers should only be written to a text file. I need help in:

  1. Writing function, which will be executed upon the start of the program (that will "fill up" available actions list.
  2. Writing a function, which will be executed, when user confirms, that he made his selection (only actions numbers should be written to a text file in the order which user selected)

I guess I could write button handler function myself; Thank you very much in advance, and excuse me, if my english is bad.

EDIT: all the action happens in a tab widget

A: 

This is one of the way by using QListWidget.

The answer for your first question is:

In the constructor of your Widget/Dialog that contains your QListWidget, add items through

void QListWidget::addItems ( const QStringList & labels )

or

void QListWidget::addItem ( const QString & label )

whichever is desired.

For the second one, you can use the following function to obtain the selected items.

QList<QListWidgetItem *> QListWidget::selectedItems () const

Then in the clicked() signal of the Arrow QPushbutton (I assume), add the Selected items into the other QListWidget using the functions given for the first answer.

Hope it helps..

liaK
Thanks, helped me a lot.
EdgeLuxe
A: 

As written in the documentation, QListView is part of the model/view framework. Be sure you have attached a model to the view and add the action to the model.

If you do not want to use the model/view framework, you can use the QListWidget class instead of QListView.

Patrice Bernassola
+1  A: 

Use two QListWidgets (http://doc.trolltech.com/4.6/qlistwidget.html), populate the left one using QListWidget::addItem, connect the clicked() signal of your QPushButton to a slot of your choosing, which could look something like this:

void myButtonClicked()
{
 // retrieve currently selected item
 QListWidgetItem *current = availableActionsList->currentItem();
 if(!current)
   return;
 // remove the item from the list of available actions
 availableActionsList->takeItem(availableActionsList->row(current));
 // and add it to the selected actions QListWidget
 selectedActionsList->addItem(availableActionsList->takeItem(current);
}

I hope that helps.

EDIT: In case you don't want to remove the item, you could simply replace the last two lines with selectedActionsList->addItem(current->text());

Greg S
Thanks, but I forgot to mention, as in the UI sketch, action doesn`t need to be removed from the available list.
EdgeLuxe
As a matter of mact it should be selected (added to the selected items box) as many times, as user wants. Could you provide me with an example for it?
EdgeLuxe
@EdgeLuxe: I updated my answer with an example for your desired behaviour.
Greg S
Thank you very much! I haven`t just found the text() funkction myself.
EdgeLuxe