Hi Lari!

No, your project file looks good. I was too tired yesterday night. There is a big speed improvement with prerendering. Just set the bool in the code to true. I don't know how I could miss that :-> But it works correctly only up to a seq_lenght of ~1800.

And if compared to a QGraphicsView solution it doesn't gain much, if anything. I'm puzzled. My graphicsview solution crashes (only in release mode) if I try to increase the seq_length to 1900. Don't know whats wrong. That seems to be the same limit, my low-level solution has, before it starts to mess up. So my guess is, that the graphicsview also prerenders the whole item into a displaylist.. hence its excellent performance!

BTW: I'm using Qt4.6 on Win7 with an ATI3850,AMD X2 6000+.

Qt Code:
  1. #ifndef MAIN_H
  2. #define MAIN_H
  3.  
  4. #include <qapplication.h>
  5. #include <qmainwindow.h>
  6. #include <qgraphicsview.h>
  7. #include <qgraphicsscene.h>
  8. #include <qgraphicsitem.h>
  9. #include <QWheelEvent>
  10. #include <QtOpenGL>
  11. #include <qmath.h>
  12. #include <qcolor.h>
  13.  
  14. using namespace std;
  15.  
  16.  
  17. class SeqMap : public QGraphicsItem
  18. {
  19. public:
  20. SeqMap(int seq_length = 1500,int num_seq = 80);
  21. QRectF boundingRect() const{ return QRectF(0, 0, data.at(0).size()*20, data.size()*20); }
  22.  
  23. void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget);
  24. private:
  25. QPixmap* textures[4];
  26. QVector< QVector<quint8> > data;
  27. };
  28.  
  29.  
  30. class MainWindow : public QMainWindow
  31. {
  32. public:
  33. MainWindow(QWidget *parent = 0);
  34. private:
  35. void wheelEvent(QWheelEvent * event);
  36.  
  37. QGraphicsView *graphicsView;
  38. };
  39.  
  40. /////////////////////
  41.  
  42. SeqMap::SeqMap(int seq_length,int num_seq)
  43. {
  44. // generate random data to display
  45. data.reserve(num_seq);
  46. QVector<quint8> seq0;
  47. seq0.reserve(seq_length);
  48. for(int j=0;j<seq_length;j++)
  49. {
  50. seq0.push_back( int(rand()/float(RAND_MAX)*4) );
  51. }
  52. data.push_back(seq0);
  53.  
  54. for(int i=1;i<num_seq;i++)
  55. {
  56. QVector<quint8> seq_i;
  57. seq_i.reserve(seq_length);
  58. for(int j=0;j<seq_length;j++)
  59. {
  60. if(rand()/float(RAND_MAX)*20 < 1)
  61. seq_i.push_back( int(rand()/float(RAND_MAX)*4) );
  62. else
  63. seq_i.push_back( data.at(0).at(j) );
  64. }
  65. data.push_back(seq_i);
  66. }
  67.  
  68. QString alpha = "ACGT";
  69. QColor tile_colors[] = { QColor("blue"), QColor("green"), QColor("yellow"), QColor("red") };
  70. // Prepare 4 textures
  71. for (quint8 i=0;i < 4;++i)
  72. {
  73. QChar base_char = alpha.at(i);
  74. QColor color = tile_colors[i];
  75. QPixmap* pmap = new QPixmap(20,20);
  76. textures[i] = pmap;
  77. QPainter painter(pmap);
  78. QBrush b = painter.brush();
  79. painter.fillRect(QRectF(0, 0, 20, 20), color);
  80. painter.setFont(QFont("Times",10));
  81. painter.setPen(QColor("black"));
  82. painter.drawText(0, 0, 20, 20,0x0084, QString(base_char));
  83. }
  84. }
  85.  
  86. void SeqMap::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  87. {
  88. Q_UNUSED(widget);
  89.  
  90. int y_pos = 0;
  91. for (int i = 0; i < data.size(); i++)
  92. {
  93. int x_pos = 0;
  94.  
  95. for (int j = 0; j < data.at(i).size(); j++)
  96. {
  97. int base = data.at(i).at(j);
  98. painter->drawPixmap(x_pos,y_pos,*textures[base]);
  99. x_pos += 20;
  100. }
  101. y_pos += 20;
  102. }
  103. }
  104.  
  105. /////////////////////
  106.  
  107. void MainWindow::wheelEvent(QWheelEvent * e)
  108. {
  109. if ( e->modifiers() == Qt::ControlModifier )
  110. {
  111. int numSteps = ( e->delta() / 8 ) / 15;
  112.  
  113. QMatrix mat = graphicsView->matrix();
  114.  
  115. if ( numSteps > 0 )
  116. mat.scale( numSteps * 1.2, numSteps * 1.2 );
  117. else
  118. mat.scale( -1 / ( numSteps * 1.2 ), -1 / ( numSteps * 1.2 ) );
  119.  
  120. graphicsView->setMatrix(mat);
  121. e->accept();
  122. }
  123. }
  124.  
  125. MainWindow::MainWindow(QWidget *parent) :
  126. QMainWindow(parent)
  127. {
  128.  
  129. // the browser stuff
  130. scene = new QGraphicsScene();
  131. scene->addItem(new SeqMap());
  132.  
  133. graphicsView = new QGraphicsView(this);
  134. graphicsView->setRenderHint(QPainter::Antialiasing, false);
  135. graphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
  136. graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState);
  137. graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
  138. graphicsView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
  139. graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
  140. graphicsView->setScene(scene);
  141. graphicsView->setGeometry(QRect(50, 50, 100, 100));
  142. graphicsView->show();
  143.  
  144. this->setCentralWidget(graphicsView);
  145.  
  146. }
  147.  
  148. #endif // MAIN_H
  149.  
  150. ---------------------------------
  151.  
  152. #include <QtCore>
  153. #include <QtGui>
  154.  
  155. #include "main.h"
  156.  
  157. int main(int argc, char *argv[])
  158. {
  159. QApplication a(argc, argv);
  160.  
  161. MainWindow w;
  162. w.show();
  163. return a.exec();
  164. }
To copy to clipboard, switch view to plain text mode 
I'll have to leave this to you. Gotta do my stuff now :->

Good luck,

Johannes