2016-05-04 74 views
3

我正在使用Qt來繪製這樣的光譜圖:在Qt中繪製陰謀的最佳方式是什麼?

spectrogram。 我也希望能夠選擇圖形的區域並編輯它們,以及滾動和縮放。

我正在考慮QGraphicsView班,但不確定其表現。據我所知,QGraphicsView中的對象是單獨存儲的,繪製大量的點可能會影響性能。

我應該用什麼Qt類來實現這個目標?

回答

1

絕對不要對每個點/標記使用QGraphicsItem。好的方法是生成代表譜圖的QPixmap,並將該像素圖作爲單個項目放入QGraphicsScene(可使用QGraphicsPixmapItem)。

要利用QPixmap請使用QPainter。也許一個小例子將是有益的:

const int spectrWidth = 1000; 
const int spectrHeight = 500; 
QPixmap spectrPixmap(spectrWidth, spectrHeight); 
QPainter p(&spectrPixmap); 

for (int ir = 0; ir < spectrHeight; ir++) 
{ 
    for (int ic = 0; ic < spectrWidth; ic++) 
    { 
     double data = getDataForCoordinates(ic, ir); // your function 
     QColor color = getColorForData(data); // your function 
     p.setPen(color); 
     p.drawPoint(ic, ir); 
    } 
} 

getDataForCoordinates()getColorForData()只是例子演示功能是如何工作的。你可能有不同的方式來獲取數據和顏色。

編輯

但是,如果你並不需要比更容易縮放/平移功能將只是直接在油漆QWidgetQWidget::paintEvent()和不使用QGraphicsView/QGraphicScene可言。

+0

我可以使用'QImage'而不是'QPixmap'嗎? –

+0

是的,你可以,但爲什麼? ...'QPixmap' *是爲在屏幕上顯示圖像而設計和優化的。* ...(來自Qt文檔) – Tomas

0

QCustomPlot是外部庫,如果您正在尋找QT原生的東西,然後看看QPainter class

相關問題