How to output Debug to Status Bar?
-
Thanks @JonB takes me a while to comprehend as I'm new to it. Would you have an example code while I figure it out for myself?
wrote on 15 Jun 2023, 16:16 last edited by@Marxsta3
But there isn't any example code because we don't know what you have got!Can you please stop writing code/testing stuff and just think/describe what it is you want? You have said that you want to be inside
mouseMoveEvent()
and show a message about what pixel is at a certain point on a pixelmap image. Right? So that must mean you have some pixmap already that you are moving the mouse over, right? Otherwise why would you want to do what you are doing? So where is thisQPixmap
which you already have and are moving the mouse over? I don't know, only you do. -
wrote on 15 Jun 2023, 16:32 last edited by
@JonB i've got an app that loads a bmp, jpg or tiff in a window. The pixmap must be used to load the image into the window. I can see it used several times. What I would like to do is load an image and then with mouse pressed down (or hovering) over the image it detects the RGB values for each pixel. I'm wanting to extract a few bits of info. The XY coordinate of the mouse, the rgb values of the pixel at that point, then later I want to adapt it to choose to allow either an rgb or cmyk image. The final status bar readings will be 1) XY coord 2) RGB (or CMYK) pixel value 3) The grey value at that point. I hope it's clearer now
-
@JonB i've got an app that loads a bmp, jpg or tiff in a window. The pixmap must be used to load the image into the window. I can see it used several times. What I would like to do is load an image and then with mouse pressed down (or hovering) over the image it detects the RGB values for each pixel. I'm wanting to extract a few bits of info. The XY coordinate of the mouse, the rgb values of the pixel at that point, then later I want to adapt it to choose to allow either an rgb or cmyk image. The final status bar readings will be 1) XY coord 2) RGB (or CMYK) pixel value 3) The grey value at that point. I hope it's clearer now
wrote on 15 Jun 2023, 16:39 last edited by JonB@Marxsta3
So whatever variable you have your pixmap already loaded into for showing, and you are moving your mouse over, is the one you want to callpix.toImage()
on inmouseMoveEvent()
. That's all there is to say and should make sense. -
@JonB i've got an app that loads a bmp, jpg or tiff in a window. The pixmap must be used to load the image into the window. I can see it used several times. What I would like to do is load an image and then with mouse pressed down (or hovering) over the image it detects the RGB values for each pixel. I'm wanting to extract a few bits of info. The XY coordinate of the mouse, the rgb values of the pixel at that point, then later I want to adapt it to choose to allow either an rgb or cmyk image. The final status bar readings will be 1) XY coord 2) RGB (or CMYK) pixel value 3) The grey value at that point. I hope it's clearer now
wrote on 15 Jun 2023, 18:14 last edited by Pl45m4@Marxsta3 said in How to output Debug to Status Bar?:
The final status bar readings will be 1) XY coord 2) RGB (or CMYK) pixel value 3) The grey value at that point. I hope it's clearer now
So basically like OpenCV's
namedWindow
with an image?
At least the Linux version shows RGB pixel values and X / Y coordinate in some status bar.You could also consider to change your design for that.
Make an image class based onQLabel
, let's call it "ImageLabel"- re-implement
mouseMoveEvent
, like you did in yourQMainWindow
class before. - enable mouseTracking
- add a signal to show it in
ImageViewer
's status bar and pass everything else you need with it (position, pixel in RGB, grayscale value)
Btw:
QImage
doesn't support the CMYK color model.QImage
is mostlyRGB(A)
,(A)RGB
orBGR
Check the formats here. - re-implement
-
@Marxsta3 said in How to output Debug to Status Bar?:
The final status bar readings will be 1) XY coord 2) RGB (or CMYK) pixel value 3) The grey value at that point. I hope it's clearer now
So basically like OpenCV's
namedWindow
with an image?
At least the Linux version shows RGB pixel values and X / Y coordinate in some status bar.You could also consider to change your design for that.
Make an image class based onQLabel
, let's call it "ImageLabel"- re-implement
mouseMoveEvent
, like you did in yourQMainWindow
class before. - enable mouseTracking
- add a signal to show it in
ImageViewer
's status bar and pass everything else you need with it (position, pixel in RGB, grayscale value)
Btw:
QImage
doesn't support the CMYK color model.QImage
is mostlyRGB(A)
,(A)RGB
orBGR
Check the formats here.wrote on 15 Jun 2023, 19:16 last edited by - re-implement
-
Oh my word @Pl45m4 that is precisely it. Would you be able to share the source code? Did you have to use OpenCV?
wrote on 15 Jun 2023, 19:29 last edited by Pl45m4@Pl45m4 said in How to output Debug to Status Bar?:
Make an image class based on QLabel, let's call it "ImageLabel"
- re-implement mouseMoveEvent, like you did in your QMainWindow class before.
- enable mouseTracking
- add a signal to show it in ImageViewer's status bar and pass everything else you need with it (position, pixel in RGB, grayscale value)
@Marxsta3 It's "just" this :)
Header
#ifndef IMAGELABEL_H #define IMAGELABEL_H #include <QLabel> #include <QMouseEvent> class ImageLabel : public QLabel { Q_OBJECT public: ImageLabel(QWidget *parent=nullptr); protected: void mouseMoveEvent(QMouseEvent* ev) override; void leaveEvent(QEvent*ev) override; signals: void mouseOverImage(QPoint px, int r, int g, int b, int gray); }; #endif // IMAGELABEL_H
code file
#include "imagelabel.h" #include <QRgb> #include <QImage> ImageLabel::ImageLabel(QWidget* parent):QLabel(parent) { setMouseTracking(true); setScaledContents(true); } void ImageLabel::mouseMoveEvent(QMouseEvent *ev) { if(pixmap() == nullptr) { QLabel::mouseMoveEvent(ev); return; } QPoint px = ev->pos(); QRgb rgb = pixmap()->scaled(this->width(), this->height()).toImage().pixel(px.x(), px.y()); int grayVal = qGray(rgb); emit mouseOverImage(ev->pos(), qRed(rgb), qGreen(rgb), qBlue(rgb), grayVal); QLabel::mouseMoveEvent(ev); } void ImageLabel::leaveEvent(QEvent *ev) { // mouse left ImageLabel // -> trigger reset on statusBar emit mouseOverImage(QPoint(), 0, 0, 0, 0); QLabel::leaveEvent(ev); }
And in your
ImageViewer
...
The string formatting is a mess, but you get the point ;)ImageLabel * imgLbl = new ImageLabel(this); connect(imgLbl, &ImageLabel::mouseOverImage, [this](QPoint p, int r, int g, int b, int gray){ QString msg = "( " + QString::number(p.x()) + " / " + QString::number(p.y()) + " )" + "\t\t\tR: " + QString::number(r) + "\tG: " + QString::number(g) + "\tB: " + QString::number(b) + "\t\t\tGRAY: " + QString::number(gray); // reset statusBar if mouse left the image if(p == QPoint()) statusBar()->clearMessage(); else statusBar()->showMessage(msg); }); QPixmap pix("Path/to/Image.jpg"); imgLbl->setPixmap(pix); setCentralWidget(imgLbl);
@Marxsta3 said in How to output Debug to Status Bar?:
Did you have to use OpenCV?
No, I said, it's like OpenCV's window
Have a look hereThis is the default window to show images using OpenCV on Ubuntu. There you can see the coordinates and RGB values from where the cursor is.
-
wrote on 15 Jun 2023, 22:08 last edited by
Great Pl45m4, it works.
Thank you everyone for your input.
-
-
21/28