2015-04-04 17 views
11

the QCustomPlot financial demo modeline benzeyen bir projede, yalnızca grafik alanına değil, grafiğin altındaki alana da bir QCPItemRect çiziyorum. this->xRect aksineQCustomPlot - QCPAxisRect öğesinin altını çizin customPlot

, dikdörtgen hala this->ui.customPlot üzerine çizilmiş olur ben Ancak

QCPItemRect * xItem = new QCPItemRect(this->ui.customPlot); 
       xItem -> setPen (QPen (Qt::black)); 

       xItem -> bottomRight ->setAxisRect(this->xRect); 
       xItem -> topLeft  ->setAxisRect(this->xRect); 

       xItem -> bottomRight ->setCoords(x - 2.0, y - 2.0); 
       xItem -> topLeft  ->setCoords(x + 2.0, y + 2.0); 

       this->ui.customPlot->addItem(xItem); 

gibi QCPItemRect eklemek istediğiniz

QCPAxisRect * xRect = new QCPAxisRect(this->ui.customPlot) 
... 
this->ui.customPlot->plotLayout()->addElement(1, 0, xRect);   

olması. Niye ya?

Herhangi bir yardım çok takdir edilir, Daniel

GÜNCELLEME cevabın bir parçayı kendim Bulunan, bir kod eksik hat

xItem -> setClipAxisRect(xRect) 

Yine sadece bazı QCPAxisRects ile çalışır olduğunu. Hâlâ orada değil. Hâlâ yok. Aşağıdaki davranış reproduces en küçük kod parçacığı olduğunu - Boş QCustomPlot projeye yapıştırabilirsiniz onun yeterince:

// create a rectAxis, put it below the main plot 
QCPAxisRect * xRect = new QCPAxisRect(this->ui.customPlot); 
       this->ui.customPlot->plotLayout()->addElement(1, 0, xRect); 

// create a rectItem and show it on the xRect  
QCPItemRect * xRectItem = new QCPItemRect(this->ui.customPlot); 

       xRectItem->setVisible   (true); 
       xRectItem->setPen    (QPen(Qt::transparent)); 
       xRectItem->setBrush   (QBrush(Qt::lightGray)); 

       xRectItem->topLeft  ->setType(QCPItemPosition::ptPlotCoords); 
       xRectItem->topLeft  ->setAxisRect(xRect); 
       xRectItem->topLeft  ->setCoords(1, 4); 

       xRectItem->bottomRight ->setType(QCPItemPosition::ptPlotCoords); 
       xRectItem->bottomRight ->setAxisRect(xRect); 
       xRectItem->bottomRight ->setCoords(2, 1); 

       xRectItem->setClipAxisRect  (xRect); 
       xRectItem->setClipToAxisRect (false);  // XXX 

       this->ui.customPlot->replot();[/code] 

davranış bağlıdır "XXX" satırı

    dışarı yorumladı olup olmadığını
  1. satırı yorum yaptı - dikdörtgenler TÜMÜNÜ YOK görüntülenmiyor.
  2. satırı sola - dikdörtgen, gösterilen şekilde here gibi ana rect çekilir.

Herhangi bir ipucu çok takdir edilir, Daniel

cevap

5

Bulunan cevap (QCustomPlot yazarı sayesinde). Eksik parçalar

  1. Ayarlar (zaten sorunun son güncelleştirmenin içerdiği) dikdörtgen
  2. Ayarlar eksenleri, dikdörtgen itaat ait clipAxisRect idi. Özellikle

,

xRectItem->setClipAxisRect  (xRect); 

ve

xRectItem->topLeft  ->setAxes(xRect->axis(QCPAxis::atBottom), xRect->axis(QCPAxis::atLeft)); 
xRectItem->bottomRight ->setAxes(xRect->axis(QCPAxis::atBottom), xRect->axis(QCPAxis::atLeft)); 
İlgili konular