1 Attachment(s)
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
Code:
ui
->treeWidget
->setVerticalScrollMode
(QListView::ScrollPerPixel);
for(int i = 0; i <= 2; i++ ) {
rootItem->setText(0, "Folder Name");
ui->treeWidget->setColumnCount(1);
ui->treeWidget->insertTopLevelItem(0, rootItem);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
//sizePolicy.setHeightForWidth(filesView->sizePolicy().hasHeightForWidth());
sizePolicy.setHeightForWidth(true);
qDebug() << sizePolicy.hasHeightForWidth();
filesView
->setLayoutMode
(QListView::SinglePass);
filesView->setLayout(layout);
filesView->setModel(filesViewModel);
filesView->ensurePolished();
//filesView->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Expanding);
filesView->setSizePolicy(sizePolicy);
filesView->setWrapping(true);
//filesView->setMinimumHeight(100);
filesView->setWordWrap(true);
qDebug() << layout->hasHeightForWidth();
qDebug() << layout->heightForWidth(200);
// this should return true
qDebug() << layout->hasHeightForWidth();
for(int j = 0; j <= 20; j++ ) {
FileWidget *fileWidget = new FileWidget;
fileWidget
->ui
->label
->setText
(QString::number(j
));
fileItem->setSizeHint(fileWidget->size());
filesViewModel->appendRow(fileItem);
filesView->setIndexWidget(fileItem->index(),fileWidget);
filesView->resize(filesView->contentsRect().width(),
filesView->heightForWidth(filesView->contentsRect().width()));
fileItem->setSizeHint(fileWidget->size());
}
childItem->setText(0, "FILES VIEW HERE");
rootItem->insertChild(0, childItem);
ui->treeWidget->setItemWidget(childItem, 0, filesView);
filesView->resize(filesView->contentsRect().width(),
filesView->heightForWidth(filesView->contentsRect().width()));
childItem->setSizeHint(0,filesView->size());
}
On the screenshot you can see the scrolls on the QListView in the CHILDs
Numbers in the List represents individual QWidgets laid out inline.
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.
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
Re: HeightForWidth always -1 QListViw
Quote:
Originally Posted by
migel
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.
Quote:
its just drive me creazy I spent 3 days to figure the proper way to it.
You are drifting the wrong way.
Re: HeightForWidth always -1 QListViw
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.
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 .
Quote:
Once I imlemented something close to what you want now.
so Have you implemented what I want ?? can you share the code ?
Re: HeightForWidth always -1 QListViw
Quote:
Originally Posted by
migel
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.
Quote:
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.
Quote:
so Have you implemented what I want ??
Probably not exactly what you want but something very similar.
Quote:
can you share the code ?
No, sorry...
Re: HeightForWidth always -1 QListViw
well, thanks but you are not helping
Re: HeightForWidth always -1 QListViw
Quote:
Originally Posted by
migel
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.