Ejemplo n.º 1
0
void MainWindow::genItemText()
{
  resetPlot();
  QCPItemText *text = new QCPItemText(customPlot);
  customPlot->addItem(text);
  text->position->setCoords(0.5, 0.5);
  text->setText("QCustomPlot\nWidget");
  text->setFont(QFont(font().family(), 24));
  text->setRotation(12);
  text->setBrush(defaultBrush);
  labelItemAnchors(text);
  customPlot->savePng(dir.filePath("QCPItemText.png"), 300, 170);
}
Ejemplo n.º 2
0
void MainWindow::setupItemAnchorTest(QCustomPlot *customPlot)
{
	customPlot->xAxis->setRange(-3, 3);
	customPlot->yAxis->setRange(-3, 3);
	customPlot->xAxis->setAutoTickCount(5);
	customPlot->yAxis->setAutoTickCount(5);

	QCPItemPixmap *pixmapItem = new QCPItemPixmap(customPlot);
	customPlot->addItem(pixmapItem);
	pixmapItem->setPixmap(QPixmap("./gnu.png"));
	pixmapItem->setScaled(true);
	pixmapItem->topLeft->setCoords(-2, 2);
	pixmapItem->bottomRight->setCoords(-1, 1);
	labelItemAnchors(pixmapItem);

	QCPItemPixmap *pixmapItem2 = new QCPItemPixmap(customPlot);
	customPlot->addItem(pixmapItem2);
	pixmapItem2->setPixmap(QPixmap("./gnu.png"));
	pixmapItem2->setScaled(true);
	pixmapItem2->topLeft->setCoords(1, 0.5);
	pixmapItem2->bottomRight->setCoords(0, 2);
	labelItemAnchors(pixmapItem2);

	QCPItemRect *rect = new QCPItemRect(customPlot);
	customPlot->addItem(rect);
	rect->topLeft->setCoords(-2, 0);
	rect->bottomRight->setCoords(-1, -0.5);
	labelItemAnchors(rect);

	QCPItemRect *rect2 = new QCPItemRect(customPlot);
	customPlot->addItem(rect2);
	rect2->topLeft->setCoords(0, -1);
	rect2->bottomRight->setCoords(-0.5, 0);
	labelItemAnchors(rect2);

	QCPItemEllipse *ellipse = new QCPItemEllipse(customPlot);
	customPlot->addItem(ellipse);
	ellipse->topLeft->setCoords(0.5, 0);
	ellipse->bottomRight->setCoords(1, -1);
	labelItemAnchors(ellipse);

	QCPItemEllipse *ellipse2 = new QCPItemEllipse(customPlot);
	customPlot->addItem(ellipse2);
	ellipse2->topLeft->setCoords(2, -1);
	ellipse2->bottomRight->setCoords(1.1, 0.2);
	labelItemAnchors(ellipse2);

	QCPItemLine *line = new QCPItemLine(customPlot);
	customPlot->addItem(line);
	line->start->setCoords(-2, -1.5);
	line->end->setCoords(-1, -1.2);
	labelItemAnchors(line);

	QCPItemCurve *curve = new QCPItemCurve(customPlot);
	customPlot->addItem(curve);
	curve->start->setCoords(0, -1.5);
	curve->startDir->setCoords(1, -1.5);
	curve->endDir->setCoords(1, -1.2);
	curve->end->setCoords(2, -1.2);
	labelItemAnchors(curve);

	QCPItemBracket *bracket = new QCPItemBracket(customPlot);
	customPlot->addItem(bracket);
	bracket->left->setCoords(-2, -2);
	bracket->right->setCoords(2, -2);
	bracket->setLength(12);
	labelItemAnchors(bracket);

	QCPItemText *text = new QCPItemText(customPlot);
	customPlot->addItem(text);
	text->position->setCoords(0, -2.6);
	text->setText("QCustomPlot");
	text->setFont(QFont(font().family(), 26));
	text->setRotation(12);
	text->setPadding(QMargins(5, 5, 40, 5));
	text->setBrush(QBrush(QColor(0, 0, 0, 30)));
	labelItemAnchors(text);
}