PDA

View Full Version : Scroll area on right side of main window



rakkar
26th August 2009, 21:28
I want to add a scroll area to the right side of my main window, the same as "Object Inspector" in QT Designer.

Every other line should be slightly darker
Each line will contain one text element
You can drag the left edge to make it bigger or smaller.
You can turn the scroll area on or off with a checkbox from the menu

I'm having a hard time understanding which elements to put down to do this. Would this be a Horizontal layout? I can't get it to attach to the right side of the window. And when I put down a Scroll area container, what goes inside? And lastly, how do I make every other line slightly darker, like Object Inspector does?

Sorry for the dumb questions. I've reread the part on the layouts several times but it hasn't made sense to me so far.

victor.fernandez
27th August 2009, 07:58
The Object Inspector is a QDockWidget (http://qt.nokia.com/doc/4.5/qdockwidget.html). You just need to add a QDockWidget to your main window. To insert a menu action that toggles the dock on or off, you may use QDockWidget::toggleViewAction() (http://qt.nokia.com/doc/4.5/qdockwidget.html#toggleViewAction).

The list of objects in the Object Inspector is a QTreeView. You will need to implement a model for it. To make every even line darker, you may set alternatingRowColors (http://qt.nokia.com/doc/4.5/qabstractitemview.html#alternatingRowColors-prop) to true.

rakkar
27th August 2009, 16:45
I added the dock view, and an item based list view inside. How do I make the item based list view always take up the entire area of the dock view? Thanks in advance.

vfernandez
27th August 2009, 18:12
In Qt Designer, you may add a layout (e.g. a vertical layout). If you're adding the view by code, use QDockWidget::setWidget().

rakkar
27th August 2009, 18:26
Is the QListWidget supposed to be a child of verticalLayout in ObjectInspector? If it's not a child the layout doesn't seem to do anything. If the QListWidget is a child, it doesn't fill the layout. It's like 1/4 of the layout, only in the center.

victor.fernandez
28th August 2009, 07:38
Just follow this procedure:

- Create a QMainWindow in Qt Designer.
- Add a dock widget.
- Add a QListWidget inside of the dock widget.
- Select the dock widget by clicking on it.
- Click the Form menu - Layout vertically.
Voièla!

Now you can resize the dock widget. The list widget will take the whole space.

rakkar
28th August 2009, 16:08
Thanks. If I want to put a label above the list widget, the label takes up half of the vertical area of the dock widget. How do I get the label to only take up the necessary size to show it? I tried changing size policy to minimum but it doesn't do anything.

vfernandez
28th August 2009, 19:02
Make sure the vertical size policy of the label is Preferred and the vertical size policy of the QListWidget is Expanding or MinimumExpanding.