April 6, 2011

runelkrone runelkrone
Lab Rat
4 posts

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 1680×1050 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

7 replies

April 7, 2011

Keith Cancel Keith Cancel
Lab Rat
14 posts

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.

 Signature 

♫♪♪^。^ Always Whistling A Tune!

April 7, 2011

Andre Andre
Area 51 Engineer
6031 posts

The ScrollArea is the way to go if you want scroll bars to appear if needed, together with using layouts [doc.qt.nokia.com] .

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

April 7, 2011

runelkrone runelkrone
Lab Rat
4 posts

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 1680×1050. 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 1152×864, 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.

April 7, 2011

Andre Andre
Area 51 Engineer
6031 posts

You should not force the window to your “needed resolution”, but you should let the window manager handle the sizing instead.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

April 7, 2011

runelkrone runelkrone
Lab Rat
4 posts

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 1680×1050. 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.

April 7, 2011

Keith Cancel Keith Cancel
Lab Rat
14 posts

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.

 Signature 

♫♪♪^。^ Always Whistling A Tune!

April 7, 2011

runelkrone runelkrone
Lab Rat
4 posts

Sorry, I guess I didn’t understand at first, but you are correct.
-Thanks

The following worked:

  1. MainWindow::MainWindow(QWidget *parent) :
  2.     QMainWindow(parent),
  3.     ui(new Ui::MainWindow)
  4. {
  5.     ui->setupUi(this);
  6.     QScrollArea* scrollArea = new QScrollArea();
  7.     this->setCentralWidget(scrollArea);
  8.  
  9.     //create the widget with elements that require scrolling to view
  10.     QWidget* widget = new CustomWidget();
  11.     scrollArea->setWidget(widget);
  12. }

 
  ‹‹ How to "fix" the transparent row-number column of a QTable?      Problem with QUdpSocket ››

You must log in to post a reply. Not a member yet? Register here!