QScrollArea
-
Hi, I need a little help with my code. I am trying to put scrollbars on my code.
It is a form that i would like to be in a groupbox and the groupbox in a qvboxlayout.@ QVBoxLayout* _layout3;
QFormLayout* layout;QScrollArea *scrollArea = new QScrollArea(this); scrollArea->setWidgetResizable(true); QGroupBox *groupBox = new QGroupBox(scrollArea); QWidget *baseArea = new QWidget(); baseArea->setLayout(_layout3); scrollArea->setWidget(baseArea); while(!patients3.isEmpty()) { QMap<QString,QString> patient = patients3.takeFirst(); if (patient["id"]==itemId) { QLineEdit *MyLineEdit = new QLineEdit(patient["id"]); layout->addRow("ID",MyLineEdit); layout->addRow("Surname", new QLineEdit(patient["surname"])); layout->addRow("Name", new QLineEdit(patient["name"])); } groupBox->setLayout(layout); scrollArea->widget()->setLayout(_layout3); this->_layout3->addWidget(groupBox); }@
-
i changed my code but the scrollbars don't show up.
@QWidget *window = new QWidget;
QScrollArea *scrollArea = new QScrollArea(this);
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scrollArea->setWidgetResizable(true);while(!patients3.isEmpty()) {
QMap<QString,QString> patient = patients3.takeFirst();
if (patient["id"]==itemId) {
QLineEdit *MyLineEdit = new QLineEdit(patient["id"]);
QFontMetrics metrics(QApplication::font());
MyLineEdit->setFixedSize(metrics.width("888888888888888888"),20);
layout->addRow("ID",MyLineEdit);
layout->addRow("Surname", new QLineEdit(patient["surname"]));
window->setLayout(layout);
scrollArea->setWidget(window);
_layout3->addWidget(window);......@Can't anybody help me????
-
I think "image viewer":http://developer.qt.nokia.com/doc/qt-4.8/widgets-imageviewer.html is good example of how to use QScrollArea providing a scrolling view around another widget (in your case window object)
-
i need little more help please
@layout = new QFormLayout;
QToolBar *toolBar = new QToolBar(this);
QSignalMapper *mapper = new QSignalMapper(this);
pagesWidget = new QStackedWidget(this);homeButton = new QToolButton(this);
page2Button = new QToolButton(this);firstPageWidget = new QWidget(this); secondPageWidget = new QWidget(this); thirdPageWidget = new QWidget(this);
_layout1 = new QVBoxLayout(this);
_layout2 = new QVBoxLayout(this);
_layout3 = new QVBoxLayout(this);_layout2->addWidget(label2); _layout3->addWidget(label3); scrollArea = new QScrollArea(this); scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); scrollArea->setWidgetResizable(true);
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(thirdPageWidget);firstPageWidget ->setLayout(_layout1);
secondPageWidget ->setLayout(_layout2);
thirdPageWidget ->setLayout(_layout3);pagesWidget->addWidget(firstPageWidget); pagesWidget->addWidget(secondPageWidget); pagesWidget->addWidget(thirdPageWidget); …. connect(mapper, SIGNAL(mapped(int)), pagesWidget, SLOT(setCurrentIndex(int))); setCentralWidget(pagesWidget); }
@
I want scrollbars only at thirdPage with _layout3, but the scrollbars are visible in all pages and they aren't at the right position. They are displayed at the left top of the window.
what can i do? -
thanks for nothing
-
[quote author="kanakas" date="1329115726"]thanks for nothing[/quote]
Yelling at volunteer fellow developers will surely make them eager to answer your questions immediately....
-
@
QWidget* firstPageWidget = new QWidget; QVBoxLayout* firstLayout = new QVBoxLayout(firstPageWidget); firstLayout->addWidget(new QLabel(tr("First widget ..."), firstPageWidget)); QWidget* secondPageWidget = new QWidget; QVBoxLayout* secondLayout = new QVBoxLayout(secondPageWidget); secondLayout->addWidget(new QLabel(tr("Second widget ..."), secondPageWidget)); QWidget* thirdPageWidget = new QWidget; thirdPageWidget->resize(2400, 2400); QVBoxLayout* thirdLayout = new QVBoxLayout(thirdPageWidget); thirdLayout->addWidget(new QLabel(tr("Third widget ..."), thirdPageWidget)); QScrollArea* scrollThirdWidget = new QScrollArea; scrollThirdWidget->setWidget(thirdPageWidget); QStackedWidget* stackedWidget = new QStackedWidget; stackedWidget->addWidget(firstPageWidget); stackedWidget->addWidget(secondPageWidget); stackedWidget->addWidget(scrollThirdWidget); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(stackedWidget); stackedWidget->setCurrentIndex(2); setCentralWidget(stackedWidget);
@
You'll see the scroll bars only in third page. If you scroll the window you'll see "Third widget..." text label.
If you change the line 24, to setCurrentIndex(0) or setCurrentindex(1) the scroll bars are not visible and you'll see the "First widget ..." or "Second widget ..." text labels always visible on first or second page. -
thank you very much!!