Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: should i use listview ?

  1. #1
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default should i use listview ?

    Hi,
    i want to see the name of all my object (with their position) [when i add object in my scene ogre i add it in the listobject)
    i use listview ?
    if that's the case , is there exemple how i do that ? or it's better to use QTreeWidget because i want when i clic of an object in the list i can do another thing

  2. #2
    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: should i use listview ?

    If you want a simple list then use a QListWidget or QListView.
    If you want a multi-column table then use a QTableWidget or QTableView.
    If you want a tree structure then use a QTreeWidget or QTreeView.

    Each xWidget includes an internal data model and the xView classes need an external model. Each xWidget is-a xView and all can respond to users clicking, double clicking etc. All follow the Model/View Programming approach.

    The documentation describes how to use theses classes and even link to examples like the Config Dialog Example

  3. #3
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: should i use listview ?

    if i use qlistview

    is there an exemple how i use it for another class

    because i define this list view in class
    Qt Code:
    1. listView = new QListView(dockWidgetContents_8);
    2. listView->setObjectName(QString::fromUtf8("listView"));
    3. listView->setGeometry(QRect(0, 0, 281, 290));
    To copy to clipboard, switch view to plain text mode 
    but how i connect it with my function
    add_object()

  4. #4
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: should i use listview ?

    you don't add object to the view you add them to the model that is connected to your view.
    you should read this, it seems complicated but in practice it is not.

    http://qt-project.org/doc/qt-4.8/mod...ogramming.html

  5. #5
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: should i use listview ?

    you don't add object to the view you add them to the model that is connected to your view.
    Sorry i did not understand
    i know that when i add in my scene (ogre) an object with add object (that work) i must see the name and position of this object in the listview
    (i did not found exemple like that)
    http://qt-project.org/doc/qt-4.8/mod...ogramming.html
    it is very complicated

  6. #6
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: should i use listview ?

    a view is the graphical representation of data.
    the data are stored in a model.
    so you need a model (a simple model would QStringListModel)
    you link the model to the view : listView->setModel(model);
    you put the info in the model (not the view) and the view will automatically update the display.

    or if you don't want to bother and don't need to display a lot of info you can use http://doc-snapshot.qt-project.org/4.8/qlistwidget.html
    it contains both model and view and is simplier, but it s slower

  7. #7
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: should i use listview ?

    i try to do that
    in my class QMainWindow
    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. .......................
    7. listView = new QListView(dockWidgetContents_8);
    8. listView->setObjectName(QString::fromUtf8("listView"));
    9. listView->setGeometry(QRect(0, 0, 281, 290));
    10.  
    11. listView->setModel(model);
    To copy to clipboard, switch view to plain text mode 

    in my class ogre widget (where i create my objects
    Qt Code:
    1. ................................................. add an object
    2. QStandardItem *item=new QStandardItem(QString ("Cube %0").arg(count));
    3.  
    4. model->setItem(count,item);
    5. QListView *listview;
    6. listview->update();
    To copy to clipboard, switch view to plain text mode 
    but it dos not work

  8. #8
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: should i use listview ?

    mmmm... you should use appendRow(item) instead of setItem
    the listview->update(); is not necessary the model should send the new info to the view into the appendRow() function
    the model pointer into the add object funtion where did you get it ?

    always use "this" as the parent pointer when you use new or you will leak

  9. #9
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: should i use listview ?

    Quote Originally Posted by Le_B View Post
    mmmm... you should use appendRow(item) instead of setItem
    the listview->update(); is not necessary the model should send the new info to the view into the appendRow() function
    the model pointer into the add object funtion where did you get it ?

    always use "this" as the parent pointer when you use new or you will leak
    yes i use appendRow but nothing it happend
    the model pointer into the add object funtion where did you get it ?
    what you mean ? i just make that
    Qt Code:
    1. listView->setModel(model);
    To copy to clipboard, switch view to plain text mode 
    always use "this" as the parent pointer when you use new or you will leak
    where i use it ?
    (sorry i know that my questions is a lot but i try to understand to do somthing good)

  10. #10
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: should i use listview ?

    1) the listview is created into the mainwindow class and you call listView->setModel(model); into the ogre widget class
    so i want to know where you got that pointer "listview" 'just to check that it comes from the mainwindow class and is the same)

    2) all QObject can have a parent QObject pointer pass as a constructor parameter. when the parent is destroyed it will automaticaly destroy his children.
    so when you do new QStandardItemModel(); you should do new QStandardItemModel(this); for exemple
    there is very few times when you don't want to do that

  11. #11
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: should i use listview ?

    so i want to know where you got that pointer "listview" 'just to check that it comes from the mainwindow class and is the same
    i did not got any pointer (i just write the same code in my repling, i read that in qt assistant exemple ) shall i define pointer ? how i do that
    so when you do new QStandardItemModel(); you should do new QStandardItemModel(this); for exemple
    ahhhh, ok i will do that

  12. #12
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: should i use listview ?

    can you put the entire function please ?

  13. #13
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: should i use listview ?

    ok
    that's the code of add_object
    Qt Code:
    1. void OgreWidget::add_object(const Ogre::Vector3 &pos)
    2. {
    3.  
    4. Ogre::String name1 = "entity " + Ogre::StringConverter::toString(Ogre::Root::getSingletonPtr()->getTimer()->getMicroseconds());
    5. mEntity = ogreSceneManager->createEntity(name1, Ogre::SceneManager:: PT_CUBE);
    6.  
    7. Ogre::MaterialPtr material1111 = Ogre::MaterialManager::getSingleton().create("green", "General");
    8.  
    9.  
    10. material1111->getTechnique( 0 )->getPass( 0 )->setAmbient(1, 1, 0);
    11. mEntity->setMaterial(material1111);
    12. Ogre::String name = "Node " + Ogre::StringConverter::toString(Ogre::Root::getSingletonPtr()->getTimer()->getMicroseconds()); // Provides a unique timestamp - the time since the application was started in microseconds.
    13. mNode = ogreSceneManager->getRootSceneNode()->
    14. createChildSceneNode(name, pos);
    15. mNode->attachObject(mEntity);
    16. count++;
    17.  
    18. QStandardItem *item=new QStandardItem(QString ("Cube %0").arg(count));
    19.  
    20. //model->setItem(count,item);
    21. model->appendRow(item);
    22. QListView *listview;
    23. listview->update();
    24.  
    25. ogreRenderWindow->update();
    26. this->update();
    27.  
    28. }
    To copy to clipboard, switch view to plain text mode 
    i just do that

  14. #14
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: should i use listview ?

    so "model" must be a member variable of OgreWidget
    and it must be set somewhere right ?

  15. #15
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: should i use listview ?

    beh
    i define model in mainwinows
    Qt Code:
    1. lass MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6.  
    7. listView = new QListView(dockWidgetContents_8);
    8. listView->setObjectName(QString::fromUtf8("listView"));
    9. listView->setGeometry(QRect(0, 0, 281, 290));
    10.  
    11. listView->setModel(model);
    To copy to clipboard, switch view to plain text mode 
    i think i bad understand how i use the "model" no? (i modifate qt assistant exemple )

  16. #16
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: should i use listview ?

    so you must have a crash when doing model->appendRow(item); in OgreWidget right ?
    if it s true it s just that you need that ogreWidget ask for the model pointer to Mainwindow, else how do you want OgreWidget to know what model is ?

  17. #17
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: should i use listview ?

    you need that ogreWidget ask for the model pointer to Mainwindow, else how do you want OgreWidget to know what model is ?
    how i do that (when i see the exemple in qt assistant it make just like that maybe because he is in the same class?)
    so how i said to ogre widget to applicate the model in mainwindows , but at first is my definition of the model in mainwinows true ?

  18. #18
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: should i use listview ?

    just create a set_model function(const QStandardItemModel *model) function in ogrewiget that will save the pointer value to a member variable
    then call it after you create the model in mainwindow (i suppose you create the ogrewidget in the same function as the model)

  19. #19
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: should i use listview ?

    i suppose you create the ogrewidget in the same function as the model)
    create model like that ?
    Qt Code:
    1. model->appendRow(item);
    To copy to clipboard, switch view to plain text mode 

  20. #20
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: should i use listview ?

    Ok , i define my model like that
    in ogrewidget.cpp
    Qt Code:
    1. QStandardItemModel* OgreWidget::add_object(/*Ogre::Real*/double offsetX ,/*Ogre::Real*/double offsetY)
    2. {
    3. .................................................
    4. model= new QStandardItemModel();
    5. int i=1;
    6. for(itr = result.begin() ;itr != result.end();++itr)
    7. {
    8. if(itr->movable)
    9. {
    10.  
    11. MarkerNode->_setDerivedPosition(mouseRay.getPoint(itr->distance));
    12. MarkerNode->setScale(0.1f, 0.1f, 0.1f);
    13. QStandardItem *item=new QStandardItem(QString ("Marker %0").arg(i));
    14. model->appendRow(item);
    15. i++;
    16.  
    17. }
    18. }
    19. return model;
    20. }
    To copy to clipboard, switch view to plain text mode 
    and in my_interface.cpp
    Qt Code:
    1. list_O = new QToolButton(page_13);
    2. list_O->setGeometry(QRect(30, 210, 101, 31));
    3. list_O->setText(QApplication::translate("MainWindow", "Object Liste", 0, QApplication::UnicodeUTF8));
    4. listView =new QListView(list_O);
    To copy to clipboard, switch view to plain text mode 
    but it still do not make to me the list

Similar Threads

  1. qml listview
    By Le_B in forum Qt Quick
    Replies: 1
    Last Post: 25th May 2011, 13:01
  2. subsection in listview
    By huluyige in forum Qt Quick
    Replies: 1
    Last Post: 25th February 2011, 10:26
  3. how do you reload a listView?
    By implor in forum Newbie
    Replies: 5
    Last Post: 16th May 2010, 22:21
  4. ListView problems
    By waitingforzion in forum Newbie
    Replies: 2
    Last Post: 26th December 2009, 00:24
  5. listview
    By addu in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2009, 12:05

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.