Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QCustomPlot adding subTicks
Forum Updated to NodeBB v4.3 + New Features

QCustomPlot adding subTicks

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 251 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dev-G
    wrote on last edited by
    #1

    Hi All,

    I am using QCustomPlot and want to do some customization for my x axis subTick labels. I have tried add a custom layer on top of main layer or grid layer, it will complains bool __cdecl QCustomPlot::moveLayer(class QCPLayer *,class QCPLayer *,enum QCustomPlot::LayerInsertMode) otherLayer not a layer of this QCustomPlot: 0

    The closest approaches is like below:

        QVector<double> subTickPositions;
        for (int i = 1; i < tickerLog->ticks().keys().size(); ++i) {
            double subTickPosition = (tickerLog->ticks().keys()[i - 1] + tickerLog->ticks().keys()[i]) / 2.0;
            subTickPositions.append(subTickPosition);
        }
        // Set custom labels for subticks if needed
        QVector<QString> subTickLabels;
        for (int i = 1; i < tickerLog->ticks().keys().size(); ++i) {
            double lower = tickerLog->ticks().values()[i - 1].toDouble();
            double upper = tickerLog->ticks().values()[i].toDouble();
            double subTickPosition = (lower + upper) / 2.0;
            subTickLabels.append(QString::number(subTickPosition));
        }
    
        // Manually draw subticks and labels
        for (int i = 0; i < subTickPositions.size(); ++i) {
            double subTickPosition = subTickPositions.at(i);
            QString subTickLabel = subTickLabels.value(i);
            // Draw label at the specified position
            QCPItemText *label = new QCPItemText(plot);
            label->position->setCoords(subTickPosition, plot->yAxis->range().lower);  // Adjust the label position
            label->setText(subTickLabel);
        }
    

    And the chart I am getting is like below (as you might see the label is being cut off by the plot's x Axis.
    15d3bc0c-fd47-47d7-9678-4a912910caf3-image.png

    Wish anyone could help!! And this is the newest version 2.1.1

    Best,

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved