2015-04-04 15 views
11

Chciałbym narysować QCPItemRect nie tylko w obszarze wykresu, ale także w obszarze pod wykresem.QCustomPlot - pokaż element na QCPAxisRect poniżej customPlot

Po

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

Chcę dodać QCPItemRect jak

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); 

Jednak prostokąt nadal pobiera rysowane na this->ui.customPlot w przeciwieństwie do this->xRect. Czemu?

Każda pomoc jest mile widziane, Daniel

UPDATE znalazł część odpowiedzi sam, jeden brakujący wiersz kodu

xItem -> setClipAxisRect(xRect) 

Nadal działa tylko z niektórymi QCPAxisRects.

AKTUALIZACJA 2 Nadal nie istnieje. Poniżej znajduje się najmniejszy fragment kodu, który odwzorowuje zachowanie - jej wystarczająco dużo, aby wkleić go do pustego projektu QCustomPlot:

// 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] 

Zachowanie zależy od tego czy linia „XXX” jest komentarzem lub nie

  1. line commented out - prostokąt nie pojawia się w ogóle.
  2. Linia w lewo - prostokąt zostanie przyciągnięty do głównego prostokąta, na przykład here.

Każda wskazówka jest mile widziane, Daniel

Odpowiedz

5

znaleźć odpowiedź (dzięki autora QCustomPlot). Brakujące elementy były

  1. Ustawienia clipAxisRect prostokąta (już zawartych w ostatniej aktualizacji pytanie)
  2. Ustawienia osie, którą wypełnia prostokąta.

szczególności

xRectItem->setClipAxisRect  (xRect); 

i

xRectItem->topLeft  ->setAxes(xRect->axis(QCPAxis::atBottom), xRect->axis(QCPAxis::atLeft)); 
xRectItem->bottomRight ->setAxes(xRect->axis(QCPAxis::atBottom), xRect->axis(QCPAxis::atLeft)); 
Powiązane problemy