PDA

View Full Version : Use QScrollBar and QLayout to display product catalog?



Kevin Hoang
11th May 2010, 04:50
I have 15000 products in database; my program will connect to this database and display a list of products. Each product is a Tool Button. Program layout is fluid layout, so I use QGridLayout to make fluid layout in this case.

Somebody help me a way to make a product list with scroll bar for above case?

Thanks!

tbscope
11th May 2010, 05:56
Why do you want to have 15000 toolbuttons?
Isn't there a better way to do this? Like a listview or treeview?
You can add buttons to views though.

Kevin Hoang
11th May 2010, 08:20
Do you mean I can use a Tree View, and change Tree Item to button? What are methods I have to override? How to handle when use click on item to see product details?

Kevin Hoang
12th May 2010, 09:56
somebody help me, pls....

Lykurg
12th May 2010, 10:05
somebody help me, pls....

Well, QGridLayout != fluid layout! Where is your problem after all? Use QSrollArea if you want srollbars, but as tbscope said: 15000 tool buttons is ... Leonidas would say: "This is madness!" :D
Better use - also as suggested - QListView with a proper model and delegate.

Kevin Hoang
13th May 2010, 06:32
Thank you...

Can you help me what model is support for this case? I try to use setIndexWidget method, but I don't know how does it works.

Lykurg
13th May 2010, 07:10
If you have a database in the background holding your data, I would go for a QSqlTableModel.

Kevin Hoang
13th May 2010, 11:58
:) I have a product table with struct like this:

id
langid
catid
fullname
shortname
image
...
description

So I want to display each product (each record) as a card on a category widget . Like this
_____________________________
|
|
| Product image
|
|
|____________________________
|
| Short name (Full Name)
|____________________________

With QSqlTableModel, I seen it not help me do like this.

Lykurg
13th May 2010, 12:13
Ehm, I will not code it for you. Have a look at the model view classes in the documentation. Also read about delegates in that content. Qt does much out of the box, but some things you must do yourself!

Kevin Hoang
13th May 2010, 13:02
I do not ask you code for me. I just want to ask a fast way for my case.

tbscope
13th May 2010, 14:43
When you want to do complex specific things, there's no fast way.

Check out this example. It will explain almost everything you need:
http://doc.qt.nokia.com/4.6/itemviews-chart.html