Results 1 to 13 of 13

Thread: How to make a ListBox?

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

    Default How to make a ListBox?

    I am making a program.. In that program i had an browze button which you can select some files from an directory.. But what a really want is a List which will have some buttons ( add file,remove file,move up,move down) so the user can select files from multiply directoories... So i searched on Qt Designer for the keyword "list" and what i have found is KEditLIstBox.... But i do not know how to use it.. Can you tell me how? Is KEditListBox the best choice?

    Please do not answer me with just a link.. That's why i asked at the Newbie section....
    Attached Images Attached Images

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

    Default Re: How to make a ListBox?

    KEditListBox is for KDE. Unless you want to write a KDE-application, I'd advise you to use QListWidget or its base class QListView instead.

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

    Default Re: How to make a ListBox?

    I do not have QListWidget but i have QListView...
    Did you see the screenshot before? That's the exact list i want...
    I do not think that QListWidget or the QListView are what i want..

  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: How to make a ListBox?

    What do you mean, you do not have QListWidget ? It's part of Qt...

    Both QListWidget and QListView will do what you want - they will provide a list of items (ListBox), which is what you ask in your topic title.

    You will of course have to add the buttons yourself, but thats the easy part

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

    Default Re: How to make a ListBox?

    yes ok.. but how with the press of the button an item be added on the listbox? ( the same with remove,move up,move down)

  6. #6
    Join Date
    May 2009
    Location
    Vienna
    Posts
    91
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make a ListBox?

    You mean/asking?
    right click the Button and select "Go TO Slot"? there you can code..

    myListbox->appenditem(..) or ->add(..) or whatever the help for the Class QListWidget says..

    greetz A.

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

    Default Re: How to make a ListBox?

    Yes i know how to go to slot :P I am not so noob..
    Anyway what are you telling me is strange.. Look, an idea is with the click of the button "ADD" search for files and then add them to the list..
    i know the first part it is simple..

    Qt Code:
    1. path = QFileDialog::getOpenFileNames(this, tr("Files"), QDir::currentPath(), tr("*.jpg *.png *.gif *.bmp"));
    To copy to clipboard, switch view to plain text mode 

    But then how to add them to the ListWidget?

  8. #8
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to make a ListBox?

    From Your posts I can only assume that You are lacking in understanding what MVC (Model View Controller) is.
    Basically QListView is a View for the model. QListView don't store Your data, it's only a way to display it to the user in list manner. (thats why this class name is *View, QTableView will display Your data in table manner, QComboBox will add combobox). The data is stored in the so called model, and simply saying it is independent (from the View) way of storing Your information/data. Idea behind this is that You can represent the same model in different way (depending on the View/Delegates).
    Examples:
    QListView:
    Snap1..jpgSnap2..jpg
    QTableView:
    Snap3..jpg
    QComboBox:
    Snap4..jpg
    Ass You can see I used the same model to display my "Data" in different way's. (depending on the needs)

    QListWidget is different then QListView, because it actually store that data that You want to display. For Your needs probably QListWidget is simplest way to go.

    Place QListWidget on the main form and use this code to add entries to the QListWidget:

    Qt Code:
    1. QStringList path = QFileDialog::getOpenFileNames(this, tr("Files"), QDir::currentPath(), tr("*.jpg *.png *.gif *.bmp"));
    2.  
    3. if( !path.isEmpty())
    4. {
    5. ui->listWidget->addItems( path );
    6. }
    To copy to clipboard, switch view to plain text mode 
    This is the simplest way to add items to the QListWidget.

    For the rest, You need to study MVC, or look as was pointed out earlier, into qt docs.
    Last edited by Talei; 29th August 2010 at 17:34.

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

    Default Re: How to make a ListBox?

    Talei thanx for your time... What i want to do isn't select some files and then copy on a path.. what i want to do is :
    When i press the add button a qfiledialog been shown ( searching for jpg,png,gif,bmp - and maybe on that filedialog when i click a picture the preview of this been show)

    Screenshot.jpg

    and then the pictures that will be selected added to the listview... not copy them somewhere just add them to the listview... .

    P.s I prefer the QListView...

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

    Default Re: How to make a ListBox?

    then you need to subclass QFileDialog first and modify to your needs, and then once you have done that create a model that the QListView will use to obtain the data. It is upto you how to handle this data, and thus you decide on the implementation for adding and moving files in the list, as you will be holding that list.

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

    Default Re: How to make a ListBox?

    You know we are on the newbie section... Can you describe it more?

  12. #12
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to make a ListBox?

    In the slot connected to the Add button you open your file dialog and, if the user does not cancel, add the selectedFiles() to the model that underlies the QListView (or add it to a QListWidget). You should look at QStringListModel if what you want to display in your list box is the paths to the selected files with (perhaps) a small icon version of the picture. You could derive from QStringListModel or QAbstractListModel to create your own model if you want to do something more advanced.

    The reference to subclassing QFileDialog above is to support your request for the file selection dialog to preview images.

    You're probably going to continue getting broad descriptions like this until you read the documentation, try the examples, and try to build your solution. Then you should be able to ask specific questions with specific answers.

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

    Default Re: How to make a ListBox?

    Quote Originally Posted by Bong.Da.City View Post
    You know we are on the newbie section... Can you describe it more?
    If we describe more you say "I'm not a noob :P", if we describe less you say "we are on the newbie section". We can't guess what you know or don't know, so we give you general advice and it's upto you to RTFM and come back with specific questions. If you don't know how to subclass an object, a good guide would be a C++ manual. If you don't know about models, then the Qt documentation talks about them plenty, and comes with lots of examples.

Similar Threads

  1. alignment in listbox
    By sk.qt in forum Qt Programming
    Replies: 7
    Last Post: 27th August 2010, 05:44
  2. Replies: 0
    Last Post: 26th June 2010, 17:13
  3. Need Listbox with Columns - which component?
    By scintillion in forum Qt Programming
    Replies: 3
    Last Post: 8th April 2010, 04:44
  4. Listbox widget
    By awanish_jmi in forum Newbie
    Replies: 1
    Last Post: 25th July 2008, 05:41
  5. ListBox view
    By mithra in forum Newbie
    Replies: 6
    Last Post: 9th January 2007, 11:57

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
  •  
Qt is a trademark of The Qt Company.