PDA

View Full Version : Scroll Area inside Dock Widget



saransiva_ps
5th August 2013, 13:25
Hi,

I've used the following code snippet to add scroll area inside dock widget



QDockWidget *m_pMapInfoWidget = new QDockWidget(this);
m_pMapInfoWidget->setObjectName(QStringLiteral("Map Info Widget"));

m_pMapInfoWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
m_pMapInfoWidget->setAllowedAreas(Qt::RightDockWidgetArea);
m_pMapInfoWidget->setMinimumSize(285, 500);

addDockWidget(Qt::RightDockWidgetArea, m_pMapInfoWidget);

// Create scroll area for the widget
QScrollArea *m_pMapInfoScrollArea = new QScrollArea();
m_pMapInfoScrollArea->setObjectName(QStringLiteral("MapInfoScrollArea"));
m_pMapInfoScrollArea->setWidgetResizable(true);
m_pMapInfoScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
m_pMapInfoScrollArea->setFrameStyle(QFrame::NoFrame);
m_pMapInfoScrollArea->show();

// Scroll area content
QWidget *m_pInfoContent = new QWidget();
m_pInfoContent->setObjectName(QStringLiteral("InfoContent"));

QGroupBox *m_pGPSGroupBox = new QGroupBox(m_pInfoContent);
m_pGPSGroupBox->setObjectName(QStringLiteral("GPSGroupBox"));
m_pGPSGroupBox->setFont(infoFont);

m_pGPSGroupBox->setTitle("Heading");
m_pGPSGroupBox->setGeometry(QRect(3, 20, 270, 170));


QLabel *m_pLatLabel = new QLabel(m_pGPSGroupBox);
m_pLatLabel->setObjectName(QStringLiteral("LatLabel"));
m_pLatLabel->setGeometry(QRect(20, 30, 51, 16));
m_pLatLabel->setFont(infoFont);
m_pLatLabel->setText("Latitude");

m_pMapInfoScrollArea->setWidget(m_pInfoContent);
m_pMapInfoWidget->setWidget(m_pMapInfoScrollArea);



When executing the above code we are getting a scroll area, but there is no scroll bar in it.
When i resize the window, we are not getting the scroll bar.
Kindly help us to resolve this.

Santosh Reddy
5th August 2013, 13:35
Show after setting the widget, like this...


//m_pMapInfoScrollArea->show(); //<<<<<<<<<<<<<<<<<<<<<<<<
...
m_pMapInfoScrollArea->setWidget(m_pInfoContent);
m_pMapInfoWidget->setWidget(m_pMapInfoScrollArea);
m_pMapInfoWidget->show()

saransiva_ps
6th August 2013, 06:35
Hi,

Thanks for the reply. After adding



m_pMapInfoWidget->show();



We are not able to get the scroll bar. After searching we found that a minimum size must be specified for the Content widget (holding the info)
to get the scroll bar. That is



m_pInfoContent->setMinimumSize(280, 1200);



Thanks