Results 1 to 10 of 10

Thread: HeightForWidth always -1 QListViw

  1. #1
    Join Date
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default HeightForWidth always -1 QListViw

    I created TreeWidget
    - node
    - child
    - node
    -child

    I implemented each child with QListView to display multiple widgets under -child. The point is that QListView height does not expend together with its content. I figured finally why, its because the layout of QListView returns -1 of the hasHeightForWith function, so the height of the QListView has always the scroll bar. How the heck resize the height base on width and the list content.

    I done it in the past resizing the height but on QLabel's not sure what's wrong with QListView.

    Please help me out. Thanks

    Qt Code:
    1. ui->treeWidget->setVerticalScrollMode(QListView::ScrollPerPixel);
    2.  
    3. for(int i = 0; i <= 2; i++ ) {
    4. QTreeWidgetItem *rootItem = new QTreeWidgetItem();
    5. rootItem->setText(0, "Folder Name");
    6. ui->treeWidget->setColumnCount(1);
    7. ui->treeWidget->insertTopLevelItem(0, rootItem);
    8.  
    9. QStandardItemModel *filesViewModel = new QStandardItemModel;
    10.  
    11. QListView *filesView = new QListView;
    12. QHBoxLayout *layout = new QHBoxLayout;
    13.  
    14. QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    15. sizePolicy.setHorizontalStretch(0);
    16. sizePolicy.setVerticalStretch(0);
    17. //sizePolicy.setHeightForWidth(filesView->sizePolicy().hasHeightForWidth());
    18. sizePolicy.setHeightForWidth(true);
    19. qDebug() << sizePolicy.hasHeightForWidth();
    20.  
    21. filesView->setLayoutMode(QListView::SinglePass);
    22. filesView->setLayout(layout);
    23. filesView->setModel(filesViewModel);
    24. filesView->ensurePolished();
    25. filesView->setViewMode(QListView::IconMode);
    26. filesView->setFlow(QListView::LeftToRight);
    27. filesView->setResizeMode(QListView::Adjust);
    28.  
    29. //filesView->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Expanding);
    30. filesView->setSizePolicy(sizePolicy);
    31.  
    32. filesView->setMovement(QListView::Free);
    33. filesView->setWrapping(true);
    34. //filesView->setMinimumHeight(100);
    35. filesView->setWordWrap(true);
    36.  
    37. qDebug() << layout->hasHeightForWidth();
    38. qDebug() << layout->heightForWidth(200);
    39. // this should return true
    40. qDebug() << layout->hasHeightForWidth();
    41.  
    42. for(int j = 0; j <= 20; j++ ) {
    43. QStandardItem *fileItem = new QStandardItem;
    44. FileWidget *fileWidget = new FileWidget;
    45. fileWidget->ui->label->setText(QString::number(j));
    46. fileItem->setSizeHint(fileWidget->size());
    47. filesViewModel->appendRow(fileItem);
    48. filesView->setIndexWidget(fileItem->index(),fileWidget);
    49. filesView->resize(filesView->contentsRect().width(),
    50. filesView->heightForWidth(filesView->contentsRect().width()));
    51.  
    52. fileItem->setSizeHint(fileWidget->size());
    53.  
    54. }
    55.  
    56. QTreeWidgetItem *childItem = new QTreeWidgetItem();
    57. childItem->setText(0, "FILES VIEW HERE");
    58. rootItem->insertChild(0, childItem);
    59. ui->treeWidget->setItemWidget(childItem, 0, filesView);
    60.  
    61. filesView->resize(filesView->contentsRect().width(),
    62. filesView->heightForWidth(filesView->contentsRect().width()));
    63.  
    64. childItem->setSizeHint(0,filesView->size());
    65.  
    66. }
    To copy to clipboard, switch view to plain text mode 

    On the screenshot you can see the scrolls on the QListView in the CHILDs
    Numbers in the List represents individual QWidgets laid out inline.
    Attached Images Attached Images
    Last edited by migel; 8th May 2011 at 18:04.

  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: HeightForWidth always -1 QListViw

    Not to spoil your fun but the proper way of doing what you are trying to obtain is implementing a custom view, possibly based on QTreeView/QTreeWidget. With your current solution you'll spend 90% of the time working around "problems" such as this one.
    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
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HeightForWidth always -1 QListViw

    I knew it, it gotta be a way to do it simply, but could not find any example and I come up that. This is QTreeWidget but the child is QListView with widgets and what U mean bu custom view, you mean custom view for a childs ? to display it next to each other instead of line by line ? Please can U give me any example how can I do it ?? its just drive me creazy I spent 3 days to figure the proper way to it.

    Thanks You

  4. #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: HeightForWidth always -1 QListViw

    Quote Originally Posted by migel View Post
    what U mean bu custom view, you mean custom view for a childs ?
    I mean a subclass of QAbstractItemView or one of its subclasses to implement the view as a whole and not to compose it of multiple widgets.

    its just drive me creazy I spent 3 days to figure the proper way to it.
    You are drifting the wrong way.
    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
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HeightForWidth always -1 QListViw

    how do I do it ?

  6. #6
    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: HeightForWidth always -1 QListViw

    First you think what you want to achieve and then you implement the virtual methods from QAbstractItemView to realize your goal. There is no easy receipe for what you want to do. It's not that much work though. Once I imlemented something close to what you want now.
    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
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HeightForWidth always -1 QListViw

    confused the above !

    How the hell I implement QAbstractItemView to ui->treeView ???????????????? examples, examples, examples please I know its possible but no idea how to do it, at least please share with me how to start .

    Once I imlemented something close to what you want now.
    so Have you implemented what I want ?? can you share the code ?

  8. #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: HeightForWidth always -1 QListViw

    Quote Originally Posted by migel View Post
    How the hell I implement QAbstractItemView to ui->treeView ????????????????
    QTreeView inherits QAbstractItemView. Basically the most important method when implementing a view is QAbstractItemView::visualRect() and also its counterpart -- QAbstractItemView::indexAt(). Start with those.

    examples, examples, examples please I know its possible but no idea how to do it, at least please share with me how to start .
    I can't show you any magic 5 lines of code that do anything practical. You can have a look at the chart example to have something to start with.

    so Have you implemented what I want ??
    Probably not exactly what you want but something very similar.
    can you share the code ?
    No, sorry...
    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.


  9. #9
    Join Date
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: HeightForWidth always -1 QListViw

    well, thanks but you are not helping

  10. #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: HeightForWidth always -1 QListViw

    Quote Originally Posted by migel View Post
    well, thanks but you are not helping
    My hourly rate is about 80 euro. You can hire me to do your job for you. I'm certainly not going to spend a couple of hours of my free time to give you a COTS product just like that as an "example". You have been told what you have to do. If you don't feel up to the task of doing it yourself then hire someone to do it for you or find a different job/hobby.
    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.


Similar Threads

  1. heightForWidth QGraphicsLayoutItem
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 20th October 2009, 09:14
  2. sizeHint() and heightForWidth(int) problem
    By nifei in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2009, 13:36
  3. heightforWidth
    By vermarajeev in forum Qt Programming
    Replies: 12
    Last Post: 11th September 2007, 13:22

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.