Originally Posted by
high_flyer
Ok.
So if I understand correctly your problem is:
Translated:
Everything works, except, that when you resize the window to have a larger width, the labels will remain narrow, is that correct?
If so, try adding a vertical spacer in the layout that holds the labels, it will "squeeze" the labels to take as much horizontal space as they can.
Nope. buddy.. in fact my problem is the vertical space. would u please create a rapid demo project in a few seconds? and you will understand it right now. Keep narrowing the windows. it will lost some characters. my test OS is windows XP.
/////////////////////////////////////////////scrollview.h//////////////////////////////////////////////////////////////
#ifndef ScrollView_H
#define ScrollView_H
#include <QtGui>
{
Q_OBJECT
public:
{
setLayout( layout );
layout->addWidget( scrollArea );
viewLayout->setAlignment( Qt::AlignTop );
view->setLayout(viewLayout);
scrollArea->setWidget( view );
scrollArea->setWidgetResizable(true);
scrollArea->verticalScrollBar()->setSingleStep( 20 );
for (int i=0; i<1; ++i)
{
label
= new QLabel("<font color='#000000' size='2'>Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi.........END_OF_LABEL</font>", view
);
label->setWordWrap(true);
label->setAutoFillBackground( true );
// QSizePolicy sp = label->sizePolicy();
// sp.setVerticalPolicy(QSizePolicy::Expanding);
// label->setSizePolicy(sp);
label->setPalette(p);
viewLayout->addWidget( label );
}
}
protected:
};
#endif // ScrollView_H
//////////////////////////////////////main.cpp/////////////////////////////////////////////////////////////////
#include "scrollview.h"
int main(int argc, char *argv[])
{
QScrollView w;
w.show();
return a.exec();
}
/////////////////////////////////////////////scrollview.h//////////////////////////////////////////////////////////////
#ifndef ScrollView_H
#define ScrollView_H
#include <QtGui>
class QScrollView : public QWidget
{
Q_OBJECT
public:
QScrollView( QWidget* parent = 0 )
{
QHBoxLayout* layout = new QHBoxLayout(this);
setLayout( layout );
scrollArea = new QScrollArea(this);
layout->addWidget( scrollArea );
view = new QWidget(scrollArea);
viewLayout = new QVBoxLayout(view);
viewLayout->setAlignment( Qt::AlignTop );
view->setLayout(viewLayout);
scrollArea->setWidget( view );
scrollArea->setWidgetResizable(true);
scrollArea->verticalScrollBar()->setSingleStep( 20 );
QLabel* label = NULL;
for (int i=0; i<1; ++i)
{
label = new QLabel("<font color='#000000' size='2'>Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi..Abc defg hi.........END_OF_LABEL</font>", view );
label->setWordWrap(true);
label->setAutoFillBackground( true );
// QSizePolicy sp = label->sizePolicy();
// sp.setVerticalPolicy(QSizePolicy::Expanding);
// label->setSizePolicy(sp);
QPalette p = label->palette();
p.setColor( QPalette::Window, QColor(255,0,255) );
label->setPalette(p);
viewLayout->addWidget( label );
}
}
protected:
QScrollArea* scrollArea;
QWidget* view;
QVBoxLayout* viewLayout;
};
#endif // ScrollView_H
//////////////////////////////////////main.cpp/////////////////////////////////////////////////////////////////
#include "scrollview.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QScrollView w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks