PDA

View Full Version : QListWidget's strings get truncated in dialog



alxobr
5th June 2011, 00:47
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 ?


DiskList::DiskList( QWidget *parent, const char *name)
: QListWidget(parent)
{
setObjectName(name);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
int nb_entries=read_entries() ;
setSelectionMode(QAbstractItemView::ExtendedSelect ion);
setResizeMode(QListView::Adjust);
for (int i = 0; i< nb_entries; i++)
addItem(new QListWidgetItem(QString(entries[i]->mntpnt) + tr(" (removable drive)")));
}

GetUpdateList::GetUpdateList( QWidget *parent)
: QDialog( parent)
{
QVBoxLayout * whole = new QVBoxLayout;
whole->setObjectName("whole");
whole->setMargin(DIALOG_MARGIN);
whole->addWidget( disklist= new DiskList( this, "disklist"), 0, 0);
whole->addSpacing(DIALOG_SPACING);
QHBoxLayout *buttons = new QHBoxLayout();
update = new QPushButton( tr("&Update"), this );
connect( update, SIGNAL(clicked()), SLOT(updatedb()) );
buttons->addWidget(update, 0, 0);
done = new QPushButton( tr("&Done"), this );
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:

setMinimumWidth(contentsRect().width() * 2 );[/QTCLASS]

do not solve the issue. Actually even the dialog's caption is truncated...

Alexandre

Added after 22 minutes:

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

ChrisW67
5th June 2011, 08:45
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.


#include <QtGui>
#include <QDebug>

const int DIALOG_MARGIN = 10;
const int DIALOG_SPACING = 10;

class DiskList: public QListWidget {
Q_OBJECT
public:
DiskList( QWidget *parent, const char *name) : QListWidget(parent) {
setObjectName(name);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
int nb_entries = 10;
setSelectionMode(QAbstractItemView::ExtendedSelect ion);
setResizeMode(QListView::Adjust);
for (int i = 0; i< nb_entries; i++)
addItem(new QListWidgetItem(QString("Entry %1").arg(i) + tr(" (removable drive)")));
}
};

class GetUpdateList: public QDialog {
Q_OBJECT
DiskList *disklist;
QPushButton *update;
QPushButton *done;
public:
GetUpdateList( QWidget *parent = 0) : QDialog( parent) {
QVBoxLayout * whole = new QVBoxLayout;
whole->setObjectName("whole");
whole->setMargin(DIALOG_MARGIN);
whole->addWidget( disklist= new DiskList( this, "disklist"), 0, 0);
whole->addSpacing(DIALOG_SPACING);
QHBoxLayout *buttons = new QHBoxLayout();
update = new QPushButton( tr("&Update"), this );
connect( update, SIGNAL(clicked()), SLOT(updatedb()) );
buttons->addWidget(update, 0, 0);
done = new QPushButton( tr("&Done"), this );
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[])
{
QApplication app(argc, argv);

GetUpdateList gul;
gul.show();
return app.exec();
}
#include "main.moc"


6518

alxobr
7th June 2011, 12:43
Hi all,


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