Autosizing scrollable window
-
Perhaps I have missed something simple, but I am having trouble designing a large window. I come from a .NET background and am used to designing windows with fixed location content. If the window size becomes smaller than the content in the window the scrollbars automatically appear and allow the user to scroll to see the rest of the window. The system is being designed for a single computer with a resolution set at 1680x1050 so I don't need much in the way of auto-layout for the components. Since my design window is much smaller, I am unable to see the extents of the screen. I tried using a scroll area, but it has a set size as well and doesn't adjust to the window size. Is it possible to have functionality similar to the windows environment? Is it built in or can someone give an example of how to implement it? If my question doesn't make sense please ask for clarification.
Thanks
-
I am not much an expert, but I know if you can place your widgets x,y location and dimensions in the .ui file with just a text editor, and quickly compile just the gui and see how it looks on the target system. I am bit confused because I can make a huge windows and use the scroll bars to see what I am designing in Qt Creator.
Or are you talking about the window when you preview it on your development machine you get no scroll bars if you make the windows cover up widgets. I would then recommend taking a scroll area and making automatically re-size to the window area then put a widget area(Or any sort of container) inside the scroll area with a minimum size. Then put widgets inside the widget area and if covered up then it should show the scroll bars you need I could be wrong as I am fairly new at this, but if I understand correctly a scroll area will respect a containers minimum size and show the scroll bars if the area of the scroll window becomes smaller than a child objects minimum size.
-
The ScrollArea is the way to go if you want scroll bars to appear if needed, together with using "layouts":http://doc.qt.nokia.com/4.7/layout.html .
-
Thanks for the previous responses, but it still isn't working.
Perhaps this shows my inexperience with Qt, but I seem to be missing something. I am programming for linux. In my design I set the main window size to my needed resolution 1680x1050. Then I add a QScrollArea to the main widget and assign a layout so that it fills the main window. Then I add the rest of my components. However, when I run the application the physical window is 1152x864, but I don't get scrollbars. If I force scrollbars to be active they appear on the edges of the 1680 resolution when I resize the window.
-
When you design the window, you have to give it an initial size (geometry). This is all I am doing. I am not trying to resize the window at run-time. My qwidget that I add to the layout of the main window is 1680x1050. I would assume that this should cause the window to show scrollbars, but it is not. Do you have a simple example that I could test that implements this? I would appreciate it.
Thanks again.
-
As I said earlier you need to add an other container widget in the scroll area, and be certain to set a minimum size(The size it takes to fill up the whole are maximized) for the container widget. Then put your buttons menus ect... in the container widget.
-
Sorry, I guess I didn't understand at first, but you are correct.
-ThanksThe following worked:
@MainWindow::MainWindow(QWidget parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QScrollArea scrollArea = new QScrollArea();
this->setCentralWidget(scrollArea);//create the widget with elements that require scrolling to view QWidget* widget = new CustomWidget(); scrollArea->setWidget(widget);
}
@