Draw basic Axes on QPixmap ?
-
Sorry you're correct, I was confusing the two of you.
No worries 😉
Why does this need to be in a class format like how you showed ? Can I not directly paint the QLabel ?
no, painting on a QLabel can only be done inside the paintEvent function. To access that function subclassing is requiert
Also I usually resize the image to the size of the label before putting it in QLabel. Now will this still be possible - won't the pixmap get cut off or over extend past the label when drawing it...
in the example the pixmap actually get’s stretched. In the end you have full control over it. But IIRC you will never be able to paint outside a Qwidgets boundaries.
———
That said, you can potentially use the QPainter on the QPixmap directly and draw the axis that way.Edit: @mrjj beat me to it, with an actual example as well 😳
-
Hi
Regarding the axis.
One option is to simply draw them in inkscape and save as SVG.
Then just paint the SVG on top of the image.
That should be faster than draw the ticks and values by hand using painter.
However, if axis values change or zoom is needed then its not good idea. -
@mrjj said in Draw basic Axes on QPixmap ?:
Hi
Regarding the axis.
One option is to simply draw them in inkscape and save as SVG.
Then just paint the SVG on top of the image.
That should be faster than draw the ticks and values by hand using painter.
However, if axis values change or zoom is needed then its not good idea.Hi, the "plot/image" is not interactive. The axis values do change but only each time a user changes a setting. So the axis would have to somehow be made on the fly for each "session". During the "session" the axis remain the same though while the image does change ! So I'm not sure what's the most efficient way of doing it...
-
@r-p-h
Well if its very dynamic then hand painting them with painter should do it.
Overlaying a svg with only part of the axis is likely more fiddle fiddle to place the values correctly
so just drawing it should be the way to go.
Do you have image of the needed axis? -
@mrjj said in Draw basic Axes on QPixmap ?:
@r-p-h
Well if its very dynamic then hand painting them with painter should do it.
Overlaying a svg with only part of the axis is likely more fiddle fiddle to place the values correctly
so just drawing it should be the way to go.
Do you have image of the needed axis?The image is live though so it's constantly being displayed in a loop, so I'm not sure if re-drawing the axes constantly is such a good idea.
-
@mrjj said in Draw basic Axes on QPixmap ?:
@r-p-h
oh, well for that sort of overlay,
you will need to draw the axis
anytime the image changes regardlessly.Hi, Surely I could just draw (or plot ?) the axes once in the beginning and then just display or draw the image inside the plot. I think that re-drawing the axes every time will be very inefficient. Also manually drawing the tick marks and values seems like it could become tedious, so maybe using some form of QChart is the way to go...
-
Hi
Well it sounds to me like the image is live ?
Like a camera feed ? -
@r-p-h
QLabel *Label_backImg = new QLabel(this);
Label_backImg->setMinimumSize(80,80);
Label_backImg->setMaximumSize(80,80);
Label_backImg->setPixmap(QPixmap(":/images/edit-icon.png").scaled (Label_backImg->width(),Label_backImg->height(),Qt::KeepAspectRatio));QLabel *labelIcon = new QLabel(Label_backImg); labelIcon->setGeometry(40,8,40,40); labelIcon->setPixmap(QPixmap(":/images/notification.png").scaled (labelIcon->width(),labelIcon->height(),Qt::KeepAspectRatio));
result image is :
-
@anil_arise said in Draw basic Axes on QPixmap ?:
@r-p-h
QLabel *Label_backImg = new QLabel(this);
Label_backImg->setMinimumSize(80,80);
Label_backImg->setMaximumSize(80,80);
Label_backImg->setPixmap(QPixmap(":/images/edit-icon.png").scaled (Label_backImg->width(),Label_backImg->height(),Qt::KeepAspectRatio));QLabel *labelIcon = new QLabel(Label_backImg); labelIcon->setGeometry(40,8,40,40); labelIcon->setPixmap(QPixmap(":/images/notification.png").scaled (labelIcon->width(),labelIcon->height(),Qt::KeepAspectRatio));
result image is :
Hi, with this approach I will have to first create the axis externally and save them as some sort of a transparent image ?
-
Thanks for the support guys. I tried making a transparent QPixmap image using Qt::transparent fill for the axis and overlaying it onto my other QPixmap, however it didn't work properly. So I ended up just drawing directly onto the image itself. Not the most efficient method but it seems to work...