Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 51

Thread: Help me on creating a List Widget...

  1. #21
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Help me on creating a List Widget...

    Quote Originally Posted by Bong.Da.City View Post
    First i want to say.. Do not give me any Class reference... I had looked many times THE class reference of listwidget and i cannot understand it...
    Then you need to overcome your inability to understand simple explanations of how things work. You could start by reading through the numerous tutorials and examples, including the source code, already available for list views, table views, the model-view architecture and related material. There's a lot of it, but you should be able to work your way from end to end in a few hours. If you focus your attention sufficiently, that should be more than enough information to let you implement your task.

    As others have said, though: don't expect other people to do the work you're unwilling to do yourself. If you want someone to code to your specifications, I occasionally take on consulting jobs. I normally charge $150 to $200 per hour for such work, with a 20 hour minimum. Let me know if you're interested, although my time is pretty much spoken for over the next month.

  2. #22
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help me on creating a List Widget...

    Quote Originally Posted by Lykurg View Post
    @squidge: You caused me a stroke with your renaming! I thought that it couldn't be that there is suddenly a guy with more than 1500 post I never have heard of. Then finally I saw your footer. Thank heaven, I am relieved. Please, don't change your name too often!
    Ha ha.... I was right when asking for the signature
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #23
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help me on creating a List Widget...

    Quote Originally Posted by wysota View Post
    Wow... two weeks just to create an editable list of files (seems like a wallpaper management app)... I think I'll go to bed now
    Actually i am not trying to make the listwisget 2 weeks... Lol..
    I do other thinks on the app...

  4. #24
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help me on creating a List Widget...

    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?

  5. #25
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help me on creating a List Widget...

    Use QListWidget::takeItem() to remove the item from the list and reinsert it again in the new position.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #26
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help me on creating a List Widget...

    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?

  7. #27
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Help me on creating a List Widget...

    Qt Code:
    1. +----------+ +----------+ +----------+
    2. | | | | | |
    3. | Item 1 | | Item 1 | | Item 1 |
    4. | Item 2 | | Item 3 | | Item 3 |
    5. | Item 3 |--> item = takeItem(2) -->| Item 4 |--> insertItem(3, item) -->| Item 2 |
    6. | Item 4 | | | | Item 4 |
    7. | | | | | |
    8. +----------+ +----------+ +----------+
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to tbscope for this useful post:

    takechi (12th November 2010)

  9. #28
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help me on creating a List Widget...

    tbscope thanks for the reply.... But look what i have done:

    Qt Code:
    1. void MainWindow::on_moveupButton_clicked()
    2. {
    3. ui->listWidget->takeItem(ui->listWidget->currentRow());
    4. ui->listWidget->insertItem(ui->listWidget->currentRow() + 1,ui->listWidget->currentRow());
    5. }
    To copy to clipboard, switch view to plain text mode 
    With errors:
    error: invalid conversion from ‘int’ to ‘const char*’
    error: initializing argument 1 of ‘QString::QString(const char*)’

  10. #29
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help me on creating a List Widget...

    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.

    Quote Originally Posted by Bong.Da.City View Post
    With errors:
    error: invalid conversion from ‘int’ to ‘const char*’
    error: initializing argument 1 of ‘QString::QString(const char*)’
    Please, please take a look at documentation of the methods you are using prior to using them and check if signatures of them match.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #30
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Help me on creating a List Widget...

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

  12. #31
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help me on creating a List Widget...

    Look what it is saying..

    QListWidgetItem * QListWidget::takeItem ( int row )

    Removes and returns the item from the given row in the list widget; otherwise returns 0.
    Items removed from a list widget will not be managed by Qt, and will need to be deleted manually.

    It doesn't say anything about taking the item and inserting it one item up...
    So how can i remove an item and then insert it without deleting it from the list?

  13. #32
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help me on creating a List Widget...

    Quote Originally Posted by Lykurg View Post
    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...
    I had understand whay tbscops says... But how to create local variables with the taken item and the row? What do you mean?

  14. #33
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help me on creating a List Widget...

    Quote Originally Posted by Bong.Da.City View Post
    But how to create local variables with the taken item and the row?
    Please do yourself (and us) a favour and learn at least a tiny bit of C++ before trying yourself against Qt. We will not teach you how to program in C++.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #34
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help me on creating a List Widget...

    wysota i had done the add,remove, and remove all button to work alone....
    But i really have no idea on how to make the move down and move up buttons to work...
    I had looked every line of the class reference ... searched on google and nothing... try it my own and nothing..

    I am sure that you probably know... So why not tell it to me? It is just 2 lines ( probably ) .. And if you hade done it another time it is just a copy paste for you...
    Finally i founded a widget that have move up and move down ( http://qt-apps.org/content/show.php/...content=125518 )

    P.s if it is a problem to post link to qt-apps tell me and i will delete the link....

  16. #35
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help me on creating a List Widget...

    Quote Originally Posted by Bong.Da.City View Post
    I had looked every line of the class reference ... searched on google and nothing... try it my own and nothing..
    It's not about the reference, it's not about google. It's about you not knowing how to do software development. You have been given all the help required, you know which methods to use but you don't know how to use them. You are asking how to create local variables and stuff like that. You can't even match types of return values of methods to argument types of other methods. Do you really consider yourself a skilled developer? You should take a piece of paper and a pencil and think about an algorithm for solving your problem - without any classes and methods, just a concept. Only then come back to a computer and implement the solution you came up with.

    So why not tell it to me? It is just 2 lines ( probably ) .. And if you hade done it another time it is just a copy paste for you...
    The more I think about it the more I come to a conclusion that you should fail your programming class for your professor to see how lousy programming teacher he is.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #36
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help me on creating a List Widget...

    Just to know that i am a 16 year old kid... I am learning programming only for 1.5 months and i already know many things..

    I am sure that you was an absolute noob on your first 1.5 months...

    I think that the newbie section is not as it should be.. When we say newbie we say newbie... Tell me when somebody says that he is a beginner how is he supposed to
    understand something when you give him a class reference.. ? He will understood with an example or a good answer..

    And the worst thing... How a beginner is supposed to try to do things when you say phrases like:

    Do you really consider yourself a skilled developer? You should take a piece of paper and a pencil and think about an algorithm for solving your problem - without any classes and methods, just a concept. Only then come back to a computer and implement the solution you came up with.

    The more I think about it the more I come to a conclusion that you should fail your programming class for your professor to see how lousy programming teacher he is.



    It suppose that you encourage beginners... ( But as i can see it is like you say that your are the best programmer and I suck... Nice )

  18. #37
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Help me on creating a List Widget...

    When we say "Newbie" we mean someone who has not used Qt before and are taking there first steps into using it. We don't mean someone whose previous programming language was BASIC or whatever (or even just standard C, for that matter).

    To learn Qt, there is a prerequisite of a good knowledge of C++, so instead of whinging on this forum you should learn C++ first, and then come back and attempt Qt.

  19. #38
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help me on creating a List Widget...

    Quote Originally Posted by Bong.Da.City View Post
    I am sure that you was an absolute noob on your first 1.5 months...
    Actually no (my first language was BASIC and I learned it quite fast myself apart from some quirks related to reading stored data using READ and DATA directives) but that's not the point. The point is you are trying to prove us that you do know how to use C++ while in reality you don't and you should learn it first before using Qt because Qt development requires you to posess some knowledge about object oriented programming and C++ in particular. Otherwise you will keep having problems such as the ones you have now.

    I think that the newbie section is not as it should be.. When we say newbie we say newbie...
    Newbie in Qt, not newbie in programming. Please take a break from Qt and spend two days studying C++. You will see how much faster you will be solving your problems.

    He will understood with an example or a good answer..
    If an example is beyond your comprehension you will not understand it nor learn from it. You could only blindly copy it but it would get you nowhere.

    It suppose that you encourage beginners... ( But as i can see it is like you say that your are the best programmer and I suck... Nice )
    I don't consider myself a "best" programmer but I consider myself a decent Qt programming teacher and somehow my students don't have problems with grasping Qt when I explain it to them. But they do have a background in C++ or some other OO language. This is something your programming teacher should have taught you before letting you work with Qt.

    If you want to become a good developer, you have to do things in the right order. You can't build a roof of a house before laying down foundations for the house. And currently you are lacking those foundations when it comes to programming.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #39
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help me on creating a List Widget...

    Ok you have right in that point wysota...
    I know that i must have knowledge of C++.. i have bought a book and it is quite well.. Because of the school i do not have any time to read it... And if i read it i will forget it as i will start programming again in 2 years because i have to focus on studying on my 2 last classes on high school... Anyway i do not have any teacher for now ( As I am 16 :P )...

    I have still 4 days to sit all day in my laptop and try to do things with my app... After this 4 days i will not use my laptop again for 2 years ( Maybe on christmas or on summer a bit) because i want to pass on a programming school here in greece... The point is that on this 4 days i would like to finish my app so i wouldn't think when i study," ohh i have so many things to do in my app "... Finishing the app includes have a List Widget to it...

    Anyway i had post this topic and i thought someone would make me a simple example, take it and understand, put it on my app and finish my app...:/

  21. #40
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help me on creating a List Widget...

    Here is the answer for move up...

    Qt Code:
    1. void MainWindow::on_moveupButton_clicked()
    2. {
    3. if( ui->listWidget->selectionModel()->hasSelection() ){
    4. if( ui->listWidget->currentIndex().row() != 0 ){
    5. int row = ui->listWidget->currentIndex().row();
    6. QModelIndex currentIndex = ui->listWidget->currentIndex();
    7. QModelIndex indexAbove = ui->listWidget->model()->index( row-1, 0, QModelIndex() );
    8.  
    9. QString selectedString = ui->listWidget->currentIndex().data().toString();
    10. ui->listWidget->model()->setData( currentIndex, indexAbove.data().toString() );
    11. ui->listWidget->model()->setData( indexAbove, selectedString );
    12. ui->listWidget->setCurrentIndex( indexAbove );
    13. }
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    Here is the answer for move down...
    Qt Code:
    1. void MainWindow::on_movedownButton_clicked()
    2. {
    3. if( ui->listWidget->selectionModel()->hasSelection() ){
    4. if( ui->listWidget->currentIndex().row() != ui->listWidget->model()->rowCount()-1 ){
    5. int row = ui->listWidget->currentIndex().row();
    6. QModelIndex currentIndex = ui->listWidget->currentIndex();
    7. QModelIndex indexBelow = ui->listWidget->model()->index( row+1, 0, QModelIndex() );
    8.  
    9. QString selectedString = ui->listWidget->currentIndex().data().toString();
    10. ui->listWidget->model()->setData( currentIndex, indexBelow.data().toString() );
    11. ui->listWidget->model()->setData( indexBelow, selectedString );
    12. ui->listWidget->setCurrentIndex( indexBelow );
    13. }
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How can I create a widget list as Qt Designer?
    By ricardo in forum Qt Programming
    Replies: 5
    Last Post: 3rd May 2009, 12:54
  2. List Widget need help!
    By patrick772goh in forum Newbie
    Replies: 1
    Last Post: 15th August 2007, 10:25
  3. Creating a widget on a QGraphicsView
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 9th August 2007, 17:54
  4. Stupid list widget won't clear
    By scwizard in forum Qt Programming
    Replies: 14
    Last Post: 5th July 2007, 16:03
  5. Custom widget in list view
    By fusoin23 in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2006, 14:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.