Beispiel #1
0
void RgbImageWindow::showAtCustomplot(QImage image)
{

    QCPItemPixmap *MyImage = new QCPItemPixmap(ui->widget);
    QPixmap pixmap = QPixmap::fromImage(image);
    MyImage->setPixmap(pixmap);
    MyImage->topLeft->setType(QCPItemPosition::ptPlotCoords);
    MyImage->bottomRight->setType(QCPItemPosition::ptPlotCoords);
    MyImage->topLeft->setCoords(ui->widget->xAxis->range().lower, ui->widget->yAxis->range().upper);
    MyImage->bottomRight->setCoords(ui->widget->xAxis->range().upper, ui->widget->yAxis->range().lower);
    MyImage->setScaled(true,Qt::IgnoreAspectRatio);
    ui->widget->addItem(MyImage);

}
Beispiel #2
0
void MainWindow::genItemPixmap()
{
  resetPlot();
  QCPItemPixmap *pixmapItem = new QCPItemPixmap(customPlot);
  customPlot->addItem(pixmapItem);
  pixmapItem->setPixmap(QPixmap("./gnu.png"));
  pixmapItem->setScaled(true, Qt::IgnoreAspectRatio);
  pixmapItem->topLeft->setCoords(-0.2, 1);
  pixmapItem->bottomRight->setCoords(0.3, 0);
  labelItemAnchors(pixmapItem);
  QCPItemPixmap *pixmapItem2 = new QCPItemPixmap(customPlot);
  customPlot->addItem(pixmapItem2);
  pixmapItem2->setPixmap(QPixmap("./gnu.png"));
  pixmapItem2->setScaled(true, Qt::IgnoreAspectRatio);
  pixmapItem2->topLeft->setCoords(1.2, 0);
  pixmapItem2->bottomRight->setCoords(0.7, 1);
  labelItemAnchors(pixmapItem2);
  customPlot->savePng(dir.filePath("QCPItemPixmap.png"), 460, 160);
}
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);
}