Re: QListWidget's strings get truncated in dialog
Hi all,
Though I have tried many things, I always get a tiny dialog with strings truncated. I can't figure out what happens. I have much more complex layouts and QListWidget's in the main window where it all works like a breeze.
Could someone tell me what I*overlooked ?
Code:
DiskList
::DiskList( QWidget *parent,
const char *name
){
setObjectName(name);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
int nb_entries=read_entries() ;
for (int i = 0; i< nb_entries; i++)
}
GetUpdateList
::GetUpdateList( QWidget *parent
){
whole->setObjectName("whole");
whole->setMargin(DIALOG_MARGIN);
whole->addWidget( disklist= new DiskList( this, "disklist"), 0, 0);
whole->addSpacing(DIALOG_SPACING);
connect( update, SIGNAL(clicked()), SLOT(updatedb()) );
buttons->addWidget(update, 0, 0);
connect( done, SIGNAL(clicked()), SLOT(accept()) );
buttons->addWidget(done, 0, 0);
whole->addLayout(buttons);
setLayout(whole);
}
Cheers,
Alexandre
-- added after 15*minutes
Hi again,
Even such instructions like:
Code:
setMinimumWidth(contentsRect().width() * 2 );[/QTCLASS]
do not solve the issue. Actually even the dialog's caption is truncated...
Alexandre
[hr]Added after 22 minutes:[/hr]
I found an ugly workaround:
[QTCLASS]void DiskList::showEvent ( QShowEvent * )
{
setMinimumWidth(2 * contentsRect().width() + 2 * frameWidth());
}
Maybe I*should rather use the width of the QListWidgetItems. However I can't believe this has to be so far fetched to get such a straightforward behavior.
Alexandre
1 Attachment(s)
Re: QListWidget's strings get truncated in dialog
The code below (which is essentially yours) produces a reasonable default size of dialog (Linux). Is yours substantially different? In any case, you can add a call to QWidget::resize() at the end of the constructor to dictate a larger starting size for the dialog.
Code:
#include <QtGui>
#include <QDebug>
const int DIALOG_MARGIN = 10;
const int DIALOG_SPACING = 10;
Q_OBJECT
public:
setObjectName(name);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
int nb_entries = 10;
for (int i = 0; i< nb_entries; i++)
}
};
class GetUpdateList
: public QDialog { Q_OBJECT
DiskList *disklist;
public:
whole->setObjectName("whole");
whole->setMargin(DIALOG_MARGIN);
whole->addWidget( disklist= new DiskList( this, "disklist"), 0, 0);
whole->addSpacing(DIALOG_SPACING);
connect( update, SIGNAL(clicked()), SLOT(updatedb()) );
buttons->addWidget(update, 0, 0);
connect( done, SIGNAL(clicked()), SLOT(accept()) );
buttons->addWidget(done, 0, 0);
whole->addLayout(buttons);
setLayout(whole);
// Want to force a particular starting size?
// resize(800, 600);
}
};
int main(int argc, char *argv[])
{
GetUpdateList gul;
gul.show();
return app.exec();
}
#include "main.moc"
Attachment 6518
1 Attachment(s)
Re: QListWidget's strings get truncated in dialog
Hi all,
Quote:
Originally Posted by
ChrisW67
The code below (which is essentially yours) produces a reasonable default size of dialog (Linux). Is yours substantially different?
Thanks a lot Chris for you help.
Hopefully I went back to the site! Having selected Subscription "Instantly, using email", I thought I'd be warned by email, and I wasn't.
I do have a substantially smaller dialog if I remove the showEvent workaround (I began to use showEvent some time ago because resize in the constructor sometimes did not work as I expected, if I remember well).
Now you can see the difference on the attached screenshot.
The code you kindly sent works fine:
addItem(new QListWidgetItem(QString("Entry %1").arg(i) + tr(" (very nice removable drive)")));
and begins to truncate the strings only when they get very large:
addItem(new QListWidgetItem(QString("Entry %1").arg(i) + tr(" (very nice removable drive which should be displayed in full)")));
My dialog already truncates much smaller strings. Parenting to 0 does not help...
Cheers,
Alexandre