It's probably a bad idea to build such a table. What is the purpose of the table?
It's probably a bad idea to build such a table. What is the purpose of the table?
I am trying to plot multiple gene sequences. The letters in each sequence, e.g. AGTCNNAG need to be aligned in a specific way, which I have been able to achieve by setting the font to fixed-width, then printing strings padded with the appropriate number of spaces. The problem with this method is a) I don't have any way of accessing individual characters - I would like to be able to make a click-event callback for each letter, and b) I don't like the look of fixed-width fonts.
I've started exploring the option of using QGraphicsView to display the characters. Does this seem like a reasonable option? The documentation claims that it can handle "millions" of objects very rapidly. Hopefully that means that it will be able to display a few thousand characters to the screen instantly. There is also the possibility of using the Model-View Framework, which is also brand new to me. Would this be the best option?
Thanks for your help!
I've been trying to use QGraphicsView with limited success. Since what I would like to do involves putting characters in a table format, it seems logical to use QGraphicsGridLayout, but I'm having trouble. So far, this is what I have:
// This works
QGraphicsScene *scene = new QGraphicsScene(this);
QGraphicsView *view = new QGraphicsView(scene);
tabs->addTab(view, "graphics");
QGraphicsTextItem *c = new QGraphicsTextItem;
c->setPlainText("bla");
scene->addItem(c); // WORKS, BUT DOESN'T USE LAYOUT
// DOESN'T WORK - Why am I not allowed to create a new QGraphicsLayoutItem?
QGraphicsGridLayout *layout = new QGraphicsGridLayout;
QGraphicsLayoutItem *layoutItem = new QGraphicsLayoutItem;
layoutItem->setGraphicsItem(c);
layout->addItem(layoutItem, 0, 0);
// DOESN'T WORK - Why not?
layout->itemAt(0,0)->setGraphicsItem(c);
Also, I am having trouble grasping when to use the "new" keyword. My understanding is that 'new' allocates dynamic memory, whereas a declaration without 'new' allocates static memory, which is freed as soon as the function exits. Yet in the example shown here , the scene is declared WITHOUT the use of "new", but QGraphicsGridLayout is declared WITH 'new'. Why?
Am I barking up the wrong tree with the QGraphicsGridLayout?
Thanks again!
Last edited by Ishmael; 29th September 2009 at 00:54. Reason: updated contents
Using the layout is ok but it's not needed in your case as you won't be doing any resizing or refitting the scene.
Here is something I crafted quickly:
Qt Code:
#include <QtGui> int main(int argc, char **argv){ QGraphicsView view; QGraphicsScene scene; view.setScene(&scene); QFont font; font.setFamily("monospace"); font.setPointSize(24); int x = 0; for(int i=0;i<text.size();i++){ item->setFont(font); scene.addItem(item); item->setPos(x, 0); x += fm.width(item->text())+fm.rightBearing(ch)+10; // +10 for additional spacing } view.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
You can control the distances between characters by adjusting x (and "y" if you want multiple rows).
Ishmael (29th September 2009)
Wow. What can i say? This is fantastic! Thank you!
Bookmarks