QCustomPlot Discussion and Comments

QCustomPlot graph width in pixelsReturn to overview

I have a roughly 4.4cm wide by 4cm in height graph, QCustomPlot mygraph->width()=390 and height() = 251
I was looking for width in pixels, 390 seems high for that small a width. Am I using incorrect property to get the pixel width? Want to thin down my plot points so I only have 1 per pixel, hence my need to know pixel width.
Thanks

The resolution of the whole screen is 480x272 so I guess the 390x251 could indeed be correct

if you want the width of the total graph, you would use mygraph->width() or mygraph->geometry(). if you want the actual drawable area of the graph, you would want mygraph->axisRect()->rect(). it sounds like you want the latter

Great. Thank you

Actually not sure that gives me what I am looking for. It returns 53 which is too small, also it seems to change randomly ... sometimes alarmingly it even returns a negative value. Any other suggestions for how many pixels wide the drawing area of a graph is??

Show the code that you're using to output, and to generate your plot.

if(event->type()==QEvent::Resize)
    {
        QStyleOptionSlider opt;
        opt.initFrom(_ui->slider);
        QRect handle = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, _ui->slider);
        QRect area=_ui->plot->axisRect()->rect();
        QRect graphGeometry=_ui->plot->geometry();
        QRect sliderGeometry=_ui->slider->geometry();
        int leftVal=area.left();
        if(!_playBackXValues.isEmpty())
            leftVal=_ui->plot->xAxis->coordToPixel(_playBackXValues.first());
        QRect newGeometry(area.left()+graphGeometry.left()-handle.width()/2.0,sliderGeometry.y(),area.width()+handle.width(),sliderGeometry.height());
        if(leftVal>0)
            newGeometry=newGeometry.adjusted(leftVal-area.left(),0,-leftVal+area.left(),0);
        _ui->slider->setGeometry(newGeometry);
        return true;
    }
    return QObject::eventFilter(watched, event);

basically my code is creating a slider that is the exact width of the graph so that it can be slid to line up with a line that we are placing in the data.

Looks like mygraph->axisRect()->rect().width gives width only if the graph has been rendered (at least once). We have many graphs which may or may not be viewed, but I still need to know pixel width count of each graph.

For now I used a default value of 200 (cause I know the pixel widths of these graph are at least that much) and if mygraph->axisRect()->rect().width yields a bigger number then I use that.

anything geometry related in qt will only work once the widget has been rendered.

So I now see ... am new to Qt and qcustomplots as is probably obvious ! Thanks all for the feedback, much appreciated.