I am new to Qt and am having difficulties with scrollbars in QWidgets.
I have a layout in a widget and the layout contains a QMenuBar. The Scroll area is associated with the widget. The scroll works fine but when the user scrolls down the Menubar goes out of sight. Is there any way to keep the Menu at the top?
Any help would be appreciated.
Thanks.
Hi @utdemir,
Thanks for quick reply.
Here is the snippit of the code with your suggestion of using QMainWindow. It produced the same results.
MyWidget::MyWidget(QMainWindow *parent)
: QMainWindow(parent)
{
main = new QWidget; //Widget that contains the layout
CreateMenu();
scrollArea = new QScrollArea;
layout = new QVBoxLayout();
//layout->setMenuBar(menuBar);
this->setMenuBar(menuBar);
this->resize(500,500);
main->setLayout(layout);
this->setCentralWidget(main);
scrollArea->setWidget(this);
scrollArea->setWidgetResizable(true);
scrollArea->show();
this->show();
}
Figured out the solution to the problem.
Created a QMainWindow which contains the menu bar. Added a QWidget which contains the layout. The scroll area is associated to the QWidget. The central widget of the mainwindow is set to be the scroll area.
Thank you for your help @utdemir