PDA

View Full Version : Grid layout



nupul
17th April 2006, 10:29
can i use a gridlayout on qlistview in a manner such that I am able to place icons on the 4 corners and the midpoints along the 4 borders of the screen/listview?


i.e

icon------------icon--------------icon
|-------------------------------------|
|-------------------------------------|
|-------------------------------------|
|-------------------------------------|
icon------------------------------ icon
|-------------------------------------|
|-------------------------------------|
|-------------------------------------|
icon------------icon--------------icon


Thanks

Nupul

jpn
18th April 2006, 15:59
No, QListView does not use any kind of layout for laying it's items.
You have a few properties to change the way how items in a list view are laid, but there is no such feature as you are looking for.

nupul
20th April 2006, 06:17
my mistake...i intended to say QListView or Grid layout. Can't I achieve the above at all in Qt...???

jpn
20th April 2006, 07:22
Writing a custom layout which allows you to lay items in corners and edges is simple enough.
Take a look at Qt's Border Layout example (http://doc.trolltech.com/4.1/layouts-borderlayout.html).
The custom layout given in the example is a good basis to start with, it doesn't need too much modifying to achieve same kind of behavior than you described.

nupul
20th April 2006, 12:50
Well thanks for the pointer. You see my custom widget is going to be of a fixed size...is there any alternative like setGeometry to position the icons exactly where i want to?

Thanks

jpn
20th April 2006, 13:47
So you have a widget which contains icons, which are also widgets right? Sure you can move the icon widgets to a fixed position if you want to.
You will have to calculate the corner/edge positions yourself, though. At least QRect contains several handy methods that.

nupul
21st April 2006, 16:43
So you have a widget which contains icons, which are also widgets right? Sure you can move the icon widgets to a fixed position if you want to.
You will have to calculate the corner/edge positions yourself, though. At least QRect contains several handy methods that.

Do i absolutely need to use QRect for this? How could I do it using Qrect...could you give me an example? ;)

Thanks

Nupul

jpn
21st April 2006, 22:15
Do i absolutely need to use QRect for this?
Heh, you absolutely don't have to use, I only mentioned I find QRect handy for this kind of calculations.. :)


How could I do it using Qrect...could you give me an example? ;)


// geometries
QRect areaRect = areaWidget->geometry(); // the whole "area"
QRect topRightRect = topRightWidget->geometry(); // the "icon" in the top right corner
QRect middleLeftRect = middleLeftWidget->geometry(); // the "icon" in the middle left edge

// top right corner
topRightRect.moveTopRight(areaRect.topRight()); // align to top right corner
topRightWidget->setGeometry(topRightRect); // move the icon widget

// middle left edge
middleLeftRect.moveCenter(areaRect.center()); // centralize
middleLeftRect.moveLeft(areaRect.left()); // align to left edge
middleLeftWidget->setGeometry(middleLeftRect); // move the icon widget

As you can see, with QRect it's simple to align items to corners/edges. ;)