Results 1 to 11 of 11

Thread: Big trouble: QScrollArea & QLabel with word wrap & Qt::AlignTop layout alignment

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    24
    Qt products
    Qt4
    Thanks
    5

    Angry Big trouble: QScrollArea & QLabel with word wrap & Qt::AlignTop layout alignment

    Hey guys.
    I need a scroll view which can add children one by one from top to bottom. and it can be auto-resized. and also the children labels will hold the whole view space. Here is the code.
    Qt Code:
    1. class QScrollView : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. QScrollView( QWidget* parent = 0 )
    7. {
    8. QHBoxLayout* layout = new QHBoxLayout(this);
    9. setLayout( layout );
    10.  
    11. scrollArea = new QScrollArea(this);
    12. layout->addWidget( scrollArea );
    13.  
    14. view = new QWidget(scrollArea);
    15. viewLayout = new QVBoxLayout(view);
    16. viewLayout->setAlignment( Qt::AlignTop );
    17. view->setLayout(viewLayout);
    18.  
    19. scrollArea->setWidget( view );
    20. scrollArea->setWidgetResizable(true);
    21. scrollArea->verticalScrollBar()->setSingleStep( 20 );
    22.  
    23.  
    24. QLabel* label = NULL;
    25. for (int i=0; i<1; ++i)
    26. {
    27. label = new QLabel("<font color='#000000' size='2'>Abc defg hi..END_OF_LABEL</font>", view );
    28. label->setWordWrap(true);
    29. label->setAutoFillBackground( true );
    30.  
    31. // QSizePolicy sp = label->sizePolicy();
    32. // sp.setVerticalPolicy(QSizePolicy::Expanding);
    33. // label->setSizePolicy(sp);
    34.  
    35. QPalette p = label->palette();
    36. p.setColor( QPalette::Window, QColor(255,0,255) );
    37. label->setPalette(p);
    38.  
    39. viewLayout->addWidget( label );
    40. }
    41. }
    42.  
    43. protected:
    44. QScrollArea* scrollArea;
    45. QWidget* view;
    46. QVBoxLayout* viewLayout;
    47.  
    48. };
    To copy to clipboard, switch view to plain text mode 

    it works well when the label has just a few characters.

    But when the label has a larger number of characters, i'm in a mess.
    To show the label's text, i must set it's Word Wrap property, right? but this will cause a problem, when i narrow the main window, the label don't show all the text. it has been cut off! finally I found that I can set the label's size policy by using "Expanding" or 'MinimumExpanding', it will solve the display problem when narrowing. but on the other side, the label dont has the fit height when i resize the window to a larger width scale. After trying all the parameters, i can't still find the answer. seeking for anyone's help now. I will greatly appreciate that!!!!
    Last edited by HiJack; 1st June 2010 at 12:03.

Similar Threads

  1. word wrap
    By deeee in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2010, 19:55
  2. KTitleWidget & word wrap
    By miraks in forum KDE Forum
    Replies: 3
    Last Post: 29th March 2009, 23:24
  3. Word wrap of QLabel
    By jimfan in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2008, 04:49
  4. Qt layouting + QLabel's word wrap = bug?
    By dimuz in forum Qt Programming
    Replies: 6
    Last Post: 5th September 2007, 11:15
  5. Word wrap in QListView
    By jiveaxe in forum Qt Programming
    Replies: 33
    Last Post: 1st September 2007, 21:06

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
  •  
Qt is a trademark of The Qt Company.