Results 1 to 20 of 51

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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....

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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.


  3. #3
    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 )

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

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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.


  6. #6
    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...:/

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

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

    See, you found a solution your own. Unfortunately it is not a good one since you change the content of two item and do not swap them. But since you are able to create local variables (row and currentIndex) you can now use the suggested functions and then you really have it.

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

    Quote Originally Posted by Lykurg View Post
    See, you found a solution your own.
    No way :-). A person who can't undestand takeItem and insertItem does not understand how to move model indexes which is conceptually more difficult.

    http://www.qtforum.org/article/34168...st-widget.html

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

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

    First i know the the takeItem and insertitem but i didn't know how to use it to move up a selected item.. Anyway yes i cannot claim that i founded my own.. Somebody ( not from here) had give me an example that he had made for somebody in the past and now i understand the hole thing...

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

    Quote Originally Posted by Bong.Da.City View Post
    and now i understand the hole thing...
    Then you don't mind explaining it?

  12. #12
    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 tbscope View Post
    Then you don't mind explaining it?
    Ok i do not mind...
    Qt Code:
    1. if( ui->listWidget->selectionModel()->hasSelection() ){
    To copy to clipboard, switch view to plain text mode 

    If you had selected something on the listWidget then do the following...

    Qt Code:
    1. if( ui->listWidget->currentIndex().row() != 0 ){
    2. int row = ui->listWidget->currentIndex().row();
    To copy to clipboard, switch view to plain text mode 

    That means that if you have selected something then int row and row will be the currentIndex.row... ( When you select for example the second item of an listWidget the row will be 2... )

    Qt Code:
    1. QModelIndex currentIndex = ui->listWidget->currentIndex();
    To copy to clipboard, switch view to plain text mode 
    currentIndex will be the item that you selected

    Qt Code:
    1. QModelIndex indexAbove = ui->listWidget->model()->index( row-1, 0, QModelIndex() );
    To copy to clipboard, switch view to plain text mode 
    indexAbove will be the item above the one you selected as it is row-1 ( we declared before that the row is the row of the selected item )

    Qt Code:
    1. QString selectedString = ui->listWidget->currentIndex().data().toString();
    To copy to clipboard, switch view to plain text mode 
    Here we convert the currentindex to string

    Qt Code:
    1. ui->listWidget->model()->setData( currentIndex, indexAbove.data().toString() );
    To copy to clipboard, switch view to plain text mode 
    Here we say to replace the current index with the indexAbove

    Qt Code:
    1. ui->listWidget->model()->setData( indexAbove, selectedString );
    To copy to clipboard, switch view to plain text mode 
    And here to replace the indexAbove with the current index

    Qt Code:
    1. ui->listWidget->setCurrentIndex( indexAbove );
    To copy to clipboard, switch view to plain text mode 
    Finnally with this function we say the one that we have selected at the start once it has gone an indexabove to be selected again..

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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...

    Three simple questions:
    1. why are you using selectionModel() and currentIndex()?
    2. what does QModelIndex() mean?
    3. what will happen if you try to move down the last item in your list?

    Or the two questions gathered into one - how are selectionModel() and currentIndex() related to QListWidget?

    By the way, your code is very likely going to misbehave once you will want to do something more than just exchange strings from items (because you are not moving any items here).
    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.


  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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...

    And that's what remains of "I will analyze it, understand it and will not copy & paste it". Sometimes I'm wondering if it makes any sense to actually help people instead of just putting out a sign "will solve Qt problems for Big Money. No questions asked".
    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. #15
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

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

    And just think of all the other people one could have helped in the time spend on this thread...

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.