Failing to add a QListView inside a QWidget
-
I am facing an issue related to displaying widgets. I have a QWidget inside which I wanna display a QListView. To illustrate further, here is the scenario:
I have a QWidget which I am adding to a vertical layout first. Then I have a class
ClipWidget
which inherits fromQWidget
. By usingQVBoxLayout
, I am setting the layout of thisWidget
as follows:@QWidget *pListWidget = new QWidget(this); QWidget *pWidget = new QWidget(this); QVBoxLayout *playoutwid = new QVBoxLayout(pWidget); playoutwid->setSpacing(0); playoutwid->addWidget(pListWidget) m_pClipWidget = new ClipWidget(pListWidget); QWidget *pClip = new QWidget(); QVBoxLayout *playout = new QVBoxLayout(pClip); playout->setSpacing(0); m_pClipWidget->setFixedHeight(120); m_pClipWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); playout->addWidget(m_pClipWidget)@
If you notice, I am passing the QWidget object in my ClipWidget class as follows:
@m_pClipWidget = new ClipWidget(pListWidget);@
I have fixed the height of
m_pClipWidget
and I have set the width as expanding. With this my intention is to have this fixedm_pClipWidget
inside a QWidgetpListWidget
.Now When I create an instance of
ClipWidget
, the constructor executes the following statements:@m_pSecondaryListView = new BinListView(this); QGridLayout *pgridlayout = new QGridLayout(this); pgridlayout->addWidget(m_pSecondaryListView);@
Here
BinListView
is a class which inherits fromQListView
. With this approach, I am looking forward to displayClipWidget
inside thepListWidget
but when I execute the code, it doesn't display.Ideally I should get a
BinListView
with the fixed height of 120 and expandable width inside a QWidget. Am I missing something???Please help :)
-
Okay, first of all: Don't mix both!
QListWidget is a simple version of QListView for people, who don't need the whole model/view functions or don't want to study that. So use QListView or QListWidget :)
Both inherts QWidget (in any way) and can be added in a layout.
-
Thanks Serenity.
I understand what you are trying to say. Actually My intention is to use QWidget and let my ListView be inside it :)
[quote author="Serenity" date="1361277884"]Okay, first of all: Don't mix both!
QListWidget is a simple version of QListView for people, who don't need the whole model/view functions or don't want to study that. So use QListView or QListWidget :)
Both inherts QWidget (in any way) and can be added in a layout.[/quote]
-
You already have things, but not in proper place. Simply do like this
@ClipWidget(QWidget * parent = 0)
: QWidget(parent)
{
m_pSecondaryListView = new QListView(this);
QGridLayout *pgridlayout = new QGridLayout(this);m_pSecondaryListView->setEditTriggers(QListView::NoEditTriggers); pgridlayout->addWidget(m_pSecondaryListView);
}@
@ClipWidget * m_pClipWidget = new ClipWidget();
m_pClipWidget->setFixedHeight(120);
m_pClipWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
m_pClipWidget->show();@ -
Thanks Santosh. But if you read the question, I want to add this "CLIPWIDGET" inside my QWidget "pListWidget". Your answer will display the ClipWidget with the fixed height oly.
[quote author="Santosh Reddy" date="1361283872"]You already have things, but not in proper place. Simply do like this
@ClipWidget(QWidget * parent = 0)
: QWidget(parent)
{
m_pSecondaryListView = new QListView(this);
QGridLayout *pgridlayout = new QGridLayout(this);m_pSecondaryListView->setEditTriggers(QListView::NoEditTriggers); pgridlayout->addWidget(m_pSecondaryListView);
}@
@ClipWidget * m_pClipWidget = new ClipWidget();
m_pClipWidget->setFixedHeight(120);
m_pClipWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
m_pClipWidget->show();@[/quote] -
Ok,
@QWidget *pListWidget = new QWidget;
QVBoxLayout *layout = new QVBoxLayout(pListWidget);ClipWidget * m_pClipWidget = new ClipWidget();
m_pClipWidget->setFixedHeight(120);
m_pClipWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);layout->addWidget(m_pClipWidget);
pListWidget->show();@