You are mistaken, in this very thread You have:
src code for custom listWidget (You can easily figure out how to do what You want to do simply analysing the code),
ChrisW67 kindly posted needed classes to complete Your task (just read description of the classes/methods),
and few others ppl are willing to help You if You ask specific question (just post some code/actual problem).
And You are wrong with first statment, You should say that You don't say thanks because no one wrote finished program for YOU.
And answer to Your question is also in one of the threads here on the forum.
In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
The advance of computerization however, has not yet wiped out nations and ethnic groups.
I do not want ready programms.. ok?
List widget is just a small part that i need for my application... Not the hole app...
I say thanks only when i solve the problem i have ..
Actually, looking back, the add button functionality is addressed the last time you asked this question:
http://www.qtcentre.org/threads/3371...make-a-ListBox
I have some problems on creating the List Widget.. For once please answer me...
I had created a List Widget.. There are five buttons.. Add,remove,remove all,move up,mode down... The add,remove and remove all buttons work perfect and do their job.. But i do not have any idea on how to make the move up button to move up the currentItem and the movedown button to move down the currentItem.. Any ideas?
Use QListWidget::takeItem() to remove the item from the list and reinsert it again in the new position.
I am using this..
ui->listWidget->takeItem(int row);
But i do not know what exactly to replace with the int row in order the current item to move up?
Qt Code:
+----------+ +----------+ +----------+ | | | | | | | Item 1 | | Item 1 | | Item 1 | | Item 2 | | Item 3 | | Item 3 | | Item 3 |--> item = takeItem(2) -->| Item 4 |--> insertItem(3, item) -->| Item 2 | | Item 4 | | | | Item 4 | | | | | | | +----------+ +----------+ +----------+To copy to clipboard, switch view to plain text mode
takechi (12th November 2010)
tbscope thanks for the reply.... But look what i have done:
With errors:Qt Code:
void MainWindow::on_moveupButton_clicked() { ui->listWidget->takeItem(ui->listWidget->currentRow()); ui->listWidget->insertItem(ui->listWidget->currentRow() + 1,ui->listWidget->currentRow()); }To copy to clipboard, switch view to plain text mode
error: invalid conversion from ‘int’ to ‘const char*’
error: initializing argument 1 of ‘QString::QString(const char*)’
If you remove an item from the list, it is no longer there so asking for currentRow() after removing the item will certainly not give you what you want.
Please, please take a look at documentation of the methods you are using prior to using them and check if signatures of them match.
after taking the item, ui->listWidget->currentRow() is not longer what you expect! Create local variables with the taken item (as in tbscops anwser!) and the row. Then handle with them.
EDIT: refresh a page before answering could be helpful...
Bookmarks