Qt4: How to get selected index in QTreeView [closed] - qt

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a program that has a tree of directories that open into subtrees of files within those directories. There are two columns in my view:
- the tree itself
- and a text column next to it that says whether the file was selected
- The user can pick multiple files at once. After the user is done selecting, when they hit the "ok" button, the text should change to "selected" next to the appropriate files.
- The problem is, I can't figure out a way to tell it which indices to change the text of. I tried selectionModel()->selectedIndexes() (and selectedRows) but neither of these have a way to get the original index far as I can tell. How could I get the original from the overall tree?

As mumush mentions, Andrea's answer applies to the QTreeWidget only, not a QTreeView. QTreeView has no selectedItems method so you have to use selectedIndexes, which will return you a list of QModelIndex objects.
You can use these objects to access and update items in your tree model like so:
# Get the fields that are currently selected and loop over them
indexes = tree.selectedIndexes()
for index in indexes:
# We only care about the "Selected" column.
if index.column() != 1:
continue
# Change the tree value.
treeModel.setData(index, "[SELECTED]")

Related

Display label based on, field on one data-source (singular) being within another data-source fields many

I am still learning, and looking for help on how to display a label based on one data-sources field value, being within another data-sources field value list.
I have one calculated table, displaying rows of documents within a folder, and wish to use a field representing the document number in that data-source, so that if it's ANYWHERE within another tables field it displays my label.
I've been trying to use projection as I think this is how to achieve it.
I can get it working based on both the current #datasouce.item.fieldnames but need it to base the calculation on all possible numbers in that tables field (Image below should make it easier to understand).
I expect that it has something to do with projections, but can't find anything within the learning templates or anywhere else to resolve the issue.
I think the following should work for you. For the 'Reserved' label have the following binding for the text property:
(#datasources.project_quotes.items..quotenumber).indexOf(#widget.datasource.item.Qnumber) !== -1 ? 'Reserved' : ''
I would suggest alternatively just to include a field in your calculated datasource and making the determination in your server script.

Foreach inside asp.net mvc5 view

I'm in need of a little help in here . I'm getting results that come from virtual property , but one row displays in multiple rows in view. How to display a record inside a row , and not in multiple records
#foreach (var item in Model.Event.Id)
appears to be your problem. You're looping over the event ID, which since it's a string, will be treated like an array of characters. Therefore it prints one character from the ID on each line, and then, because of the rest of the code, repeats all the other details of that event on each line.
Since you only appear to have one single Event in your Model, it seems that you do not need any kind of loop here at all.
However it's not entirely clear what your intentions are - perhaps you intended to loop over something else in your model which is not shown. If so, please clarify the question and possibly the answer could be expanded.

How do I select multiple instances which fulfill the WHERE clause?

Let's say I have a database which has the names of all the ships.
If I wish to select all the ships which have minimum of 10 guns, I'd do.
SELECT Class AS Class,Country.
FROM Classes
WHERE numGuns >=10;
However, I wish to select all ships and print them out who have numGuns >= 10, I've tried googling myself out of this however I haven't found something simple to work with and work from there.
Any help is appreciated.
This is just to get the question out of the list of unanswered questions
(and close-voting did not help).
The problem is caused by the simple mistake of trying to list the ship attributes "class" and "country", according to the attribute "numGuns" from a class table (which at least does not have all of these attributes) instead of from a ship table (where they exist).

How to get the selected value of checkboxlist by using Request.Form[]

I have used a CheckBoxList which ID is "FavouriteGenres". After submitting the form, another aspx page wants to get the selected values. When I debug the code, the key of the parameters have changed to "FavouriteGenres$1","FavouriteGenres$2" and so on(It represents all my selected item). The question is How to get all the selected values rather than get them one by one?
There are some pretty good answers here:
Checkbox list checked values
Let me know if you still have a question on this.

Pulling data into a RadioButtonList including randomizing how it is displayed

I'm new to programming, so bear with me as I try to explain what I"m needing to do. This is in ASP.net iwth VB. I have a quiz project that I've been assigned for work. This quiz project contains two main SQL Databases it pulls the info from.
First is a Quiz table, which contains three columns: QuizID (Pri Key), Title, Description. This is where I declare the quizzes, indicated by the QuizID (1, 2, 3....etc)
The second table is the Questions table, containing the following columns: QuestionsID (Pri Key), Title, Answer1, Answer2, Answer3, Answer4, Answer5, CorrectAnswer, QuestionOrder, QuizID
The QuizID in the Quesitons table matches the QuizID in the Quiz table. Thus for QuizID = 1, it consists of all the questions with the matching QuizID in the Questions table. The CorrectAnswer I want to assign a simple value (1, 2, 3...etc).
I need a way to take a set of questions (based on the QuizID) put them in some sort of table and randomize them (or rather shuffle them) so that each time this quiz is taken, it pulls all questions randomly, but not repeating any)
I then want the code to pull the question and coorepsonding answers to pick from in a radiobuttonlist. However, It only needs to pull the number of answers. Example, a True/False will only have Answer1 and Answer2. The other Answers will have the NULL value in it.
There needs to then be a way to go through each one of these questions that have been placed in the table (in that random order) using a "next" button. When a question and possible answwers are displayed, I alaready have code to keep the answers in the session to grade it at the end (using correctAnswer and selected answer.
I have no specific way to bind the data to the Database. I have used SQLDataSource to make other connections before, but I don't know if this is the best way.
Thanks in advance for any advice. As I said, I'm a noob, so providing all the code will be helpful.
Can you provide any sample code to demonstrate the approach that you wish to take. I am willing to help you learn and fix bugs, but I wont write all your code for you.

Resources