如何定製QPainterPath的繪圖算法?定製QWidget上的QPaintPath繪圖算法
我想通過僅繪製可見元素來加速我的應用程序。
我借鑑QPainterPath實時圖表,想做到這一點:
- 二進制搜索QPainterPath的最左側可視元素。
- 二進制搜索QPainterPath最右邊的可見元素。
- 僅繪製可見元素。
我想我應該通過QWidget::paintEngine()
來定製QWidget的QPaintEngine。
但是QPaintEngine::drawPath(...)
默認執行does nothing。
我對嗎?
UPDATE:
感謝respounce,Koying。
我剛剛tryed這樣:
int minIndex = BinarySearchForMatchOrGreat(path, beginOffset);
int maxIndex = BinarySearchForMatchOrGreat(path, endOffset);
QPainterPath newPath;
for (int i = minIndex; i < maxIndex; i++)
{
const QPainterPath::Element & element = path.elementAt(i);
newPath.moveTo(element.x, element.y);
}
painter.drawPath(newPath);
所有作品太好了!我有固定的時間開銷爲任何元素計數。
你有什麼建議來加快我的代碼嗎?
UDPATE:
我有錯誤,而閱讀QPainterPath並從另一個線程將元素添加到它。 有時應用程序崩潰與調用堆棧:!
QtCored4.dll qt_message_output(QtMsgType MSGTYPE,爲const char * BUF)線2240 C++ QtCored4.dll qt_message(QtMsgType MSGTYPE,爲const char *味精,字符* AP)線2298 + 0x12字節C++ QtCored4.dll!qFatal(const char * msg,...)行2481 + 0xf字節C++ QtCored4.dll!qt_assert(const char *斷言,const char *文件,int行)行1999 + 0x16字節C++ QtGuid4.dll!QPainterPath :: elementAt(int i)行405 + 0x36字節C++ MyPlot.dll!MyPlot :: paintEvent(QPaintEvent * event)行172 + 0x13字節C++
while calling elementAt(i),i == 4303 and there are 5459 elements。
也許元素計數是不是真正的崩潰時刻?
當第一個線程崩潰時,第二個線程可以修改元素數量嗎?
這是如何工作我的線程: 我的gui線程只使用只讀方法。 我的第二個線程每秒增加1-5000個點。
或者我需要QPainterPath的子類來修改它的行爲? – k06a 2012-03-06 09:23:47
如果您在其他線程中修改了QPainterPath,那麼您將遇到麻煩......您將不得不添加互斥鎖 – Koying 2012-03-06 16:12:02
「迭代」是什麼意思?我只使用elementAt()和elementCount()方法... – k06a 2012-03-06 18:20:23