Results 1 to 3 of 3

Thread: QListWidget's strings get truncated in dialog

  1. #1
    Join Date
    May 2011
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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 ?

    Qt Code:
    1. DiskList::DiskList( QWidget *parent, const char *name)
    2. : QListWidget(parent)
    3. {
    4. setObjectName(name);
    5. setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    6. int nb_entries=read_entries() ;
    7. setSelectionMode(QAbstractItemView::ExtendedSelection);
    8. setResizeMode(QListView::Adjust);
    9. for (int i = 0; i< nb_entries; i++)
    10. addItem(new QListWidgetItem(QString(entries[i]->mntpnt) + tr(" (removable drive)")));
    11. }
    12.  
    13. GetUpdateList::GetUpdateList( QWidget *parent)
    14. : QDialog( parent)
    15. {
    16. QVBoxLayout * whole = new QVBoxLayout;
    17. whole->setObjectName("whole");
    18. whole->setMargin(DIALOG_MARGIN);
    19. whole->addWidget( disklist= new DiskList( this, "disklist"), 0, 0);
    20. whole->addSpacing(DIALOG_SPACING);
    21. QHBoxLayout *buttons = new QHBoxLayout();
    22. update = new QPushButton( tr("&Update"), this );
    23. connect( update, SIGNAL(clicked()), SLOT(updatedb()) );
    24. buttons->addWidget(update, 0, 0);
    25. done = new QPushButton( tr("&Done"), this );
    26. connect( done, SIGNAL(clicked()), SLOT(accept()) );
    27. buttons->addWidget(done, 0, 0);
    28. whole->addLayout(buttons);
    29. setLayout(whole);
    30. }
    To copy to clipboard, switch view to plain text mode 


    Cheers,

    Alexandre

    -- added after 15*minutes
    Hi again,

    Even such instructions like:
    Qt Code:
    1. setMinimumWidth(contentsRect().width() * 2 );[/QTCLASS]
    2.  
    3. do not solve the issue. Actually even the dialog's caption is truncated...
    4.  
    5. Alexandre
    6.  
    7. [hr]Added after 22 minutes:[/hr]
    8.  
    9. I found an ugly workaround:
    10. [QTCLASS]void DiskList::showEvent ( QShowEvent * )
    11. {
    12. setMinimumWidth(2 * contentsRect().width() + 2 * frameWidth());
    13. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by Lykurg; 5th June 2011 at 09:40. Reason: changed [qtclass] to [code]

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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.
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. const int DIALOG_MARGIN = 10;
    5. const int DIALOG_SPACING = 10;
    6.  
    7. class DiskList: public QListWidget {
    8. Q_OBJECT
    9. public:
    10. DiskList( QWidget *parent, const char *name) : QListWidget(parent) {
    11. setObjectName(name);
    12. setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    13. int nb_entries = 10;
    14. setSelectionMode(QAbstractItemView::ExtendedSelection);
    15. setResizeMode(QListView::Adjust);
    16. for (int i = 0; i< nb_entries; i++)
    17. addItem(new QListWidgetItem(QString("Entry %1").arg(i) + tr(" (removable drive)")));
    18. }
    19. };
    20.  
    21. class GetUpdateList: public QDialog {
    22. Q_OBJECT
    23. DiskList *disklist;
    24. QPushButton *update;
    25. QPushButton *done;
    26. public:
    27. GetUpdateList( QWidget *parent = 0) : QDialog( parent) {
    28. QVBoxLayout * whole = new QVBoxLayout;
    29. whole->setObjectName("whole");
    30. whole->setMargin(DIALOG_MARGIN);
    31. whole->addWidget( disklist= new DiskList( this, "disklist"), 0, 0);
    32. whole->addSpacing(DIALOG_SPACING);
    33. QHBoxLayout *buttons = new QHBoxLayout();
    34. update = new QPushButton( tr("&Update"), this );
    35. connect( update, SIGNAL(clicked()), SLOT(updatedb()) );
    36. buttons->addWidget(update, 0, 0);
    37. done = new QPushButton( tr("&Done"), this );
    38. connect( done, SIGNAL(clicked()), SLOT(accept()) );
    39. buttons->addWidget(done, 0, 0);
    40. whole->addLayout(buttons);
    41. setLayout(whole);
    42.  
    43. // Want to force a particular starting size?
    44. // resize(800, 600);
    45. }
    46. };
    47.  
    48.  
    49. int main(int argc, char *argv[])
    50. {
    51. QApplication app(argc, argv);
    52.  
    53. GetUpdateList gul;
    54. gul.show();
    55. return app.exec();
    56. }
    57. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    dialog.png

  3. #3
    Join Date
    May 2011
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListWidget's strings get truncated in dialog

    Hi all,

    Quote Originally Posted by ChrisW67 View Post
    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
    Attached Images Attached Images

Similar Threads

  1. Unicode strings int Qt 4.2.1
    By mkrentovskiy in forum Qt Programming
    Replies: 12
    Last Post: 29th December 2011, 09:02
  2. Qt Printing QTextDocument problem (truncated text)
    By giowck in forum Qt Programming
    Replies: 3
    Last Post: 20th April 2011, 07:37
  3. Avoiding Truncated Labels
    By ChrisW67 in forum Qwt
    Replies: 5
    Last Post: 7th July 2009, 07:34
  4. QFile resized files gets truncated after writing
    By MaximA in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2008, 17:23
  5. QGroupBox title truncated on both sides
    By Gopala Krishna in forum Qt Programming
    Replies: 2
    Last Post: 7th October 2006, 15:02

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.