PDA

View Full Version : Scrollbar always grayed out



Gargolissimus
6th July 2009, 19:13
Hello,

i used QtDesigner for placing a QScrollArea into a QWidget and placing a QGridLayout into this QScrollArea. Now i add QLabels into the GridLayout


QLabel *lab = new QLabel();
lab->setPixmap(QPixmap::fromImage(img));
lab->setMinimumSize(img.size());
m_ui.gridLayout->addWidget(lab, m_currentRow, m_currentColumn);
}

The Labels are added and displayed correctly, but if i add more labels than my Widget can display, the scrollbars (ScrollbarAlwaysOn) are still grayed out.
What has to be done?

Thanks in advance
Garg

wysota
6th July 2009, 19:18
set the "widgetResizable" property of the scroll area to true.

Gargolissimus
6th July 2009, 20:27
it is true...

here is the code generated from QtDesigner



QScrollArea *scrollArea;
QWidget *scrollAreaWidgetContents;
QWidget *gridLayoutWidget;
QGridLayout *gridLayout;

void setupUi(QWidget *ImageViewerClass)
{
//...
scrollArea = new QScrollArea(ImageViewerClass);
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(scrollArea->sizePolicy().hasHeightForWidth());
scrollArea->setSizePolicy(sizePolicy);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn );
scrollArea->setWidgetResizable(true);
scrollAreaWidgetContents = new QWidget();

gridLayoutWidget = new QWidget(scrollAreaWidgetContents);
gridLayout = new QGridLayout(gridLayoutWidget);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
gridLayout->setContentsMargins(0, 0, 0, 0);
scrollArea->setWidget(scrollAreaWidgetContents);


I dont know where i can find more information (looked into api, qt-book, goole)

wysota
6th July 2009, 20:32
And how do you add the labels to the widget? Could you post the ui file? Mine is attached and works fine.

Gargolissimus
6th July 2009, 20:40
they are added at runtime


void ImageViewer::addImage(const QImage &img)
{
QLabel *lab = new QLabel();
lab->setPixmap(QPixmap::fromImage(img));
lab->setMinimumSize(img.size());
m_ui.gridLayout->addWidget(lab, m_currentRow, m_currentColumn);

}

mine makes it the indirect way about "GridLayoutWidget"

Gargolissimus
6th July 2009, 21:22
Now i coded it manually without using VS Integration and it works ;-) seems to generate stupid code?

ty