PDA

View Full Version : QGraphicsView problem



ayanda83
13th March 2014, 11:27
Hi everyone, i am working on an app that reads data from a database and displays the data on a QGraphicsRectItem (at least that is whats the app is suppose to do). My problem is that i am clueless as to how to implement the above. I am able to add a simple rectangular item in the QGraphacsView using QGraphicsRectItem and QGraphicsScene but beyond that i am clueless. I have read the Qt documentation but there is not enough information for me to realize my goal or maybe i'm just not understanding the Qt documentation. OK, NOW THIS IS WHAT I WANT TO ACHIEVE, the app must read a person's name and surname from the database and then display that information in a rectangular item in the GraphicsView. The rect item must be aligned to the top left-hand corner of the GraphicsView and scaling the whole width of the GraphicsView and only 10mm in height. If an extra name and surname is read from the database another identical rectItem is to be created and placed below the previous one, hence forming some kind of an array like structure. NB: When GraphicsView is scaled up, down, left or right the rectItems are to scale with the graphicsView. I DON'T EXPECT SOMEBODY TO RIGHT THE CODE FOR ME but i would appreciate it if somebody can tell me which Class objects I can use for all the above. THANKING YOU IN ADVANCE.

anda_skoa
13th March 2014, 12:51
Which parts other then creating the rectangle have you tried already?

The part where you get data from the database sounds completely solvable stand alone, i.e. can be tested without GUI or with simple widget GUI, see QSqlQuery

The visualization can also be implemented and tested without the database access, see QGraphicsItem and subclasses

Cheers,
_

ayanda83
13th March 2014, 13:43
thank you for your reply anda_skoa, reading data from the database is not a problem, the problem is creating the rectangles.

anda_skoa
13th March 2014, 14:09
You write that you already managed to create a rectangle item and add it to the scene.
So what kind of problem do you have with it?

Cheers,
_

ayanda83
13th March 2014, 14:58
the problem i have is aligning the rectangle item to the top left-hand corner of the GraphicsView and then make the rectangles item's length be the same size as the GraphicsView's length size.

anda_skoa
13th March 2014, 17:30
QGraphicsView::mapToScene() methods should help you with that.

Cheers,
_