Results 1 to 14 of 14

Thread: QListView not showing all items in the model

  1. #1
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question QListView not showing all items in the model

    Qt: 4.6.2 Commercial
    Windows XP

    My QListView is not showing all the items in the model even when scrolling to the end. The only way to see all items is to enlarge the window (QDockWidget) to the point beyond where the scrollbar goes away.

    I've not seen anything like this mentioned in the posts here, so I believe there is some setup requirement for QListView that I am not using. Has anyone seen anything like this?

    How can I get the view to display all my icons in the model?

    I'm using a QListView (in IconMode) which is being fed by a QStandardModel, very simple.

    Qt Code:
    1. setIconSize( QSize( 32, 32 ) );
    2. setViewMode( QListView::IconMode );
    3. setGridSize( QSize( 100, 80 ) );
    4. setResizeMode( QListView::Adjust );
    5. setSelectionRectVisible( true );
    6. setSpacing( 40 );
    7. setFont( QFont( "Tahoma", 8.25 ) );
    8. setVerticalScrollMode( QAbstractItemView::ScrollPerItem );
    9.  
    10. // NOTE: the dragDropMode must be set AFTER the viewMode!!!
    11. setDragEnabled( true );
    12. setDragDropMode( QAbstractItemView::DragOnly );
    13. setSelectionMode( QAbstractItemView::ExtendedSelection );
    To copy to clipboard, switch view to plain text mode 

    Loading the model:

    Qt Code:
    1. QStandardItem* pItem = new QStandardItem( sDevName );
    2. pItem->setToolTip( sDevName );
    3. pItem->setData( QVariant( icon ), Qt::DecorationRole );
    4. pItem->setData( QVariant( sCategory ), DEVDATA_CATEGORY );
    5. pItem->setData( QVariant( sDeviceDCID ), DEVDATA_DCID );
    6. m_pDevLibModel->appendRow( pItem );
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: QListView not showing all items in the model

    Haven't you by any chance forgotten to put your listview in a layout?
    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. The following user says thank you to wysota for this useful post:

    mclark (1st September 2010)

  4. #3
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView not showing all items in the model

    I just add it to a QTabWidget. It scrolls but not to the necessary extent.

    So... I need my view in a layout to accomplish that.

    Thanks, I'll give it a try.

  5. #4
    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: QListView not showing all items in the model

    You definitely forgot a layout in the tab widget's tab holding the list view.
    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. #5
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView not showing all items in the model

    I obviously am missing some knowledge here. I've added my view to a layout. Added the tab widget and set the layout on that tab. No obvious change in the scrolling of the view.

    Since layouts are not widgets I've created a QWidget in order to add a new tab to the QTabWidget.

    Qt Code:
    1. // Add the views to layouts
    2. QVBoxLayout* pDevLibLayout = new QVBoxLayout;
    3. pDevLibLayout->addWidget( m_pDevLibLst );
    4.  
    5. // ...
    6.  
    7. // Add the tabs
    8. int nTabIdx = m_pDevLibTab->addTab( new QWidget, DL_TAB_ALLDEVS_STR );
    9. m_pDevLibTab->widget( nTabIdx )->setLayout( pDevLibLayout );
    To copy to clipboard, switch view to plain text mode 

    I also tried explicitly adding the layout the the QWidget used to create the new tab.

    Qt Code:
    1. QVBoxLayout* pDevLibLayout = new QVBoxLayout;
    2. pDevLibLayout->addWidget( m_pDevLibLst );
    3. QWidget* pDevLibWidget = new QWidget;
    4. pDevLibWidget->setLayout( pDevLibLayout );
    5.  
    6. m_pDevLibTab->addTab( pDevLibWidget, DL_TAB_ALLDEVS_STR );
    To copy to clipboard, switch view to plain text mode 

    What is it that I'm not seeing here?

  7. #6
    Join Date
    Jul 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListView not showing all items in the model

    are you sure you need an extra layout here? Since you did not post how you added you list last time, was it like

    Qt Code:
    1. m_pDevLibTab->addTab(m_pDevLibLst,"some title");
    To copy to clipboard, switch view to plain text mode 

    I did not work too much with listViews yet, but when I e.g. add a QToolBox as a tab to a QTabWidget, the compiler complains if I add an additional layout: QToolBox already has a layout by default. It works perfectly without setting any layout. Maybe this is different for QListViews......

  8. #7
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView not showing all items in the model

    Quote Originally Posted by Gh0str1d3r View Post
    are you sure you need an extra layout here? Since you did not post how you added you list last time, was it like
    Qt Code:
    1. m_pDevLibTab->addTab(m_pDevLibLst,"some title");
    To copy to clipboard, switch view to plain text mode 
    Well... that is indeed how I first tried adding my QListView to the tab widget.

    wysota's suggestion about layouts seems reasonable, although I don't know if QTabWidgets have a built-in default layout. If they do, it wasn't working for some reason. If not, I have not been able to make it work by adding one.

    No compiler complaints when adding the layout explicitly.

  9. #8
    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: QListView not showing all items in the model

    If the only widget in your tab widget's tab is the list itself then passing the list view to the addTab() method is enough. Maybe I was wrong about the layout, although I don't think so. Could you post a screenshot of what you have?
    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. #9
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView not showing all items in the model

    wysota, this is what I found in the docs for QTabWidget, which seems to verify you're original suggestion of adding a layout.

    The normal way to use QTabWidget is to do the following:

    1. Create a QTabWidget.
    2. Create a QWidget for each of the pages in the tab dialog, but do not specify parent widgets for them.
    3. Insert child widgets into the page widget, using layouts to position them as normal.
    4. Call addTab() or insertTab() to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut.
    The first image shows all 18 icons.
    The second image has the scrollbar all the way down and the last 3 icons are missing (no sorting).
    Attached Images Attached Images

  11. #10
    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: QListView not showing all items in the model

    Are you using your own model? If so, did you check it with the model tester class available from labs?
    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. #11
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView not showing all items in the model

    I am using a QStandardItemModel.

    While I couldn't find any references to the model tester class on the Qt website (if you know of a link would you please provide), I am quite sure that all my data (icons/text) are in the model because the view will show all the items if the containing window is large enough.

    It seems like the scrollbar is just as confused as I am

  13. #12
    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: QListView not showing all items in the model

    Quote Originally Posted by mclark View Post
    I am using a QStandardItemModel.

    While I couldn't find any references to the model tester class on the Qt website (if you know of a link would you please provide),
    http://labs.trolltech.com/page/Proje...view/Modeltest

    It seems like the scrollbar is just as confused as I am
    Or maybe those items are added later and something is preventing the model or the view from refreshing. I'm almost sure that if you change the resize mode of your list to Fixed, those items will be missing as well.
    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. The following user says thank you to wysota for this useful post:

    mclark (2nd September 2010)

  15. #13
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView not showing all items in the model

    Or maybe those items are added later and something is preventing the model or the view from refreshing. I'm almost sure that if you change the resize mode of your list to Fixed, those items will be missing as well.
    You are correct about the Fixed resize mode not showing the items.

    The (22) items are added during the apps initialization. When the main window becomes visible the model has been filled. No other items are added after that.

    Thank you for the link, I shall try the ModelTest code you referenced.

    In the meantime, I have done my own simple test; dumped the output from a loop through my model after each item addition.

    Qt Code:
    1. for ( int i = 0; i < m_pDevLibModel->rowCount(); i++ )
    2. {
    3. for ( int j = 0; j < m_pDevLibModel->columnCount(); j++ )
    4. {
    5. pItem = m_pDevLibModel->item( i, j );
    6. qDebug( " [%d,%d] 0x%x \"%s\"", i, j,
    7. pItem, pItem->text().toAscii().data() );
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    After the final item addition, the code yields 22 entries in the model:
    [0,0] 0x3856f88 "Unknown Device"
    [1,0] 0x3856508 "CEM+ Rack 3"
    [2,0] 0x3852628 "CEM+ Rack 14"
    [3,0] 0x384ed58 "CEM+ Rack 10"
    [4,0] 0x385a0d8 "CEM+"
    [5,0] 0x3858f20 "CEM3"
    [6,0] 0x385c020 ""
    [7,0] 0x14ddb10 "CEM+ Rack 2"
    [8,0] 0x15d9ea0 "Paradigm ACP"
    [9,0] 0x3864fa8 "CEM+ Rack 1"
    [10,0] 0x3870898 "CEM+ Rack 4"
    [11,0] 0x3863948 "CEM+ Rack 5"
    [12,0] 0x154aba0 "CEM+ Rack 6"
    [13,0] 0x386fd88 "DMX/RDM 4-Port Gateway"
    [14,0] 0x3874060 "CEM+ Rack 16"
    [15,0] 0x385ce00 "CEM+ Rack 7"
    [16,0] 0x14fb748 "CEM+ Rack 11"
    [17,0] 0x3878940 "CEM+ Rack 12"
    [18,0] 0x38688a0 "CEM+ Rack 13"
    [19,0] 0x3869d78 "CEM+ Rack 8"
    [20,0] 0x387c2f0 "CEM+ Rack 15"
    [21,0] 0x387d548 "CEM+ Rack 9"

  16. #14
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView not showing all items in the model (SOLVED)

    SOLVED!

    My QListView sub-class constructor called setSpacing( 40 ) after calling setGridSize(). While I'm not sure why this upset the normal scrolling of the view, the calls clearly were interfering with each other. Commenting out the setSpacing() call solved the problem.

    Qt Code:
    1. DevLibView::DevLibView( QWidget* pParent ) : QListView( pParent )
    2. {
    3. setViewMode( QListView::IconMode );
    4. setIconSize( QSize( 32, 32 ) );
    5. setGridSize( QSize( 100, 80 ) );
    6. setResizeMode( QListView::Adjust );
    7. setSelectionRectVisible( true );
    8. //setSpacing( 40 );
    9. setFont( QFont( "Tahoma", 8.25 ) );
    10.  
    11. // NOTE: the dragDropMode must be set AFTER the viewMode!!!
    12. setDragEnabled( true );
    13. setDragDropMode( QAbstractItemView::DragOnly );
    14. setSelectionMode( QAbstractItemView::ExtendedSelection );
    15. }
    To copy to clipboard, switch view to plain text mode 
    The view now scrolls as expected (without having to add a layout to my tab widget)!

    Thank you wysota and Gh0str1d3r for your time and suggestions.
    Last edited by mclark; 2nd September 2010 at 21:10. Reason: solved problem

Similar Threads

  1. QBstractTableMode derived model, not showing in QTableView
    By high_flyer in forum Qt Programming
    Replies: 4
    Last Post: 24th March 2010, 15:04
  2. Replies: 4
    Last Post: 7th August 2009, 21:09
  3. designer not showing menu items ...
    By wagmare in forum Installation and Deployment
    Replies: 0
    Last Post: 24th February 2009, 10:26
  4. QListView is not showing contnet
    By hrudhay in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 21st August 2008, 07:31
  5. QComboBox not showing all items
    By musikit in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2008, 16:01

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.