Results 1 to 16 of 16

Thread: GridView without reflow

  1. #1
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default GridView without reflow

    Hi guys,

    I'm facing a problem implementing a map viewer with QML and a C++ model (Qt 5.2). The model is ok.
    For the view I'm using GridView and I found that it reflows contents as you resize the app window. I would like to cancel this behaviour and being able to just scroll vertically and horizontally in case the map is too big to fit in the window, but I don't know how. I tried to use a Grid with a Repeater, but the Repeater seems to place items randomly and, even if I could manage to use it correctly, it instantiates all image tiles when loaded (with a zoom level of 19 in Open Street Map there are more than 500.000 x 500.000 image tiles).

    Do you have any suggestions?

    Thanks

    EDIT: I just understood that GridView is a ListView but with reflow. Any other idea for a bidimensional view? Already tried TableView without success
    Last edited by shaolin; 11th May 2014 at 18:39.

  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: GridView without reflow

    An option is to use a bare Flickable and implement element instantiating/destruction manually as the content is scrolled.
    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
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: GridView without reflow

    Thank you for the answer.

    I'm considering this option, but in general I would like to implement a simple view for QAbstarctTableModel, maybe using a Flickable. I found a lot of documentation on implementing a model, but I can't find A clear guide on how to implement a simple model

  4. #4
    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: GridView without reflow

    You mean "a simple view"? With Qt Quick you basically have two options -- do it in C++ or in QML (or a hybrid approach). The biggest problem is to make a decision on how to handle the model. I think in Qt5 (Qt Quick 2) most of the models used in QML are actually subclasses of QAbstractItemModel (this is not the case with Qt Quick 1) but there is no guarantee on that (e.g. an array is also considered a model in Qt Quick) so you can either force a QAbstractItemModel subclass or provide a more relaxed definition of a model. Since therre is no common view definition in Qt Quick (compared to the widget world where you have QAbstractItemView) you will have to attach to model signals manually. In your particular situation what you surely need is information about data insertion and removal to the model (unless you want to make your view wok with stationary models only). Then it is just a matter of two things:
    1. fetching info from the model
    2. managing items (delegates) providing visualisation of the model data

    contentX and contentY will give you information about the current area visible in the view so that you can instantiate and destroy delegates according to your needs.
    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.


  5. #5
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: GridView without reflow

    For simple I mean that my model is fed by network requests, so I just need to react to the dataChanged signal.
    What I would like to avoid is manually creating, arranging and destroying delegates when the view moves (both in c++ and in QML).
    The only reason to prefer QML is that Image has the asynchronous option that is quite useful.

    Anyway, is there any example on how to subclass QAbstractItemModel?

  6. #6
    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: GridView without reflow

    Quote Originally Posted by shaolin View Post
    For simple I mean that my model is fed by network requests, so I just need to react to the dataChanged signal.
    dataChanged is emitted when data for existing items changes. If new items are added to the model then this results in other signals being emitted (e.g. rowsInserted).

    What I would like to avoid is manually creating, arranging and destroying delegates when the view moves (both in c++ and in QML).
    That's what implementing a view is all about.

    The only reason to prefer QML is that Image has the asynchronous option that is quite useful.
    You can load images in C++ asynchronically as well with the use of QtConcurrent.

    Anyway, is there any example on how to subclass QAbstractItemModel?
    There are many examples of subclassing a model available in Qt docs. However what I understood is that you already had a model.
    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.


  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: GridView without reflow

    When creating models for lists or tables then using one of the intermediate helper classes (QAbstractListModel, QAbstractTableModel) is a good way to start, since they implement some of the functionality that is abstract in QAbstractItemModel.

    The problem with GridView is that it basically works on a list model, not a table. I think QtQuick.Controls has a table view though.

    Cheers,
    _

  8. #8
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: GridView without reflow

    Sorry, I mean QAbstractItemView and not QAbstractItemModel. Are there example of subclassing QAbstractItemView?

    @anda_skoa I already tried QML TableView but with no succes..

  9. #9
    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: GridView without reflow

    Quote Originally Posted by shaolin View Post
    Sorry, I mean QAbstractItemView and not QAbstractItemModel. Are there example of subclassing QAbstractItemView?
    Yes, there is an example showing how to implement a chart view. But if you already have a table model and then why don't you use QTableView with a custom delegate?
    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.


  10. #10
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: GridView without reflow

    I tried with a QML TableView (should be very similar), but it displays just a column with a single tile. Probably I'm doing something wrong. how would you do it?

  11. #11
    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: GridView without reflow

    I didn't mean QML's TableView. I meant C++ QTableView. You said that the only reason to use QML for you is asynchronous loading of images and this can be easily achieved in C++ so I don't see why you wouldn't use QTableView where you only need to implement a custom delegate.
    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.


  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: GridView without reflow

    single column sounds like you have a list model.
    What does the model's columnCount() method return when you call it in C++?

    Since you wrote about OpenStreetMap, have you had a look at Marble? http://marble.kde.org/dev-intro.php

    Cheers,
    _

  13. #13
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: GridView without reflow

    Oh sorry, you are right. In the end I will use it in QML, so if I have to implement the full view, I can export it as a QML Component. But if I just implement a delegate for QTableView, than I will not be able to export the full view in QML.

    @anda: building Marble on Mac Os X is a hell, I tried..

  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: GridView without reflow

    If you want a custom view in QML then there is no base type to build upon, you have to implement all communication with the model by yourself.
    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
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: GridView without reflow

    I think so too. But before this I will try 2 things:
    creating a QML view using an horizontal ListView in which every element delegate is a vertical ListView.
    If this will not work I could try to subclass QTableView, implementing its custom delegate, and exporting my QTableView subclass as a QML component...

  16. #16
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: GridView without reflow

    Quote Originally Posted by shaolin View Post
    @anda: building Marble on Mac Os X is a hell, I tried..
    In which case I would get in touch with the Marble developers.

    Not only is a specialized for displaying maps and has all the related functionality that you would otherwise have to implement itself, it is also almost certainly that there is work to use it at least with QtQuick1 (I have marble on a Nokia N9, with pinch zoom, etc) and I wouldn't be surprised if there is at least a plan on making it work with QtQuick2.

    I've used libmarblewidget in a widget based desktop application and was very glad that I only had to concern myself with the application speciifc data I needed to drow on top of the map.

    Cheers,
    _

Similar Threads

  1. Replies: 7
    Last Post: 9th September 2013, 08:31
  2. QML GridView load model from C++ SQLite
    By olegdim in forum Qt Quick
    Replies: 0
    Last Post: 21st August 2012, 19:01
  3. QML gridView crahes on QDeclerativeView close
    By mots_g in forum Qt Programming
    Replies: 0
    Last Post: 4th June 2011, 12:28
  4. Usage of QTableView as gridview
    By ada10 in forum Newbie
    Replies: 7
    Last Post: 9th August 2010, 23:13
  5. Replies: 1
    Last Post: 14th October 2007, 10:09

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.