I'm working on qt5 (C +).
I use QVideoWidget to play rtsp video stream. I wanted to draw any signatures with QPainter on the displayed video. However, I obscure the video while drawing. For example, as for the drawing area, I have given half of the QVideoWidget image.
example used:
Tried adding an extra QLabel on QVideoWidget:
QLabel * label = new QLabel (ui-> videoWidget);
And then draw on the "label", but also cover the QVideoWidget.
I also added:
ui-> videoWidget-> setAttribute (Qt :: WA_X11OpenGLOverlay);
But then the transparency extends all the way to the desktop of the operating system.
Try to set the transparency of the item that you want to draw and not the transparency of the QVideoWidget.
Related
After a long search for the answer and a lot of testing I have not been able to place a QWidget (QLabel with a semitransparent image) over a QtGstreamer widget.
When I add an QLabel with an image over the QGst::Ui::VideoWidget (which displays video from RTP stream) the area covere with the label is black and does not display the video (which is playing).
I uploaded the project to GitHub https://github.com/MatijaBosnic/QtGstOverlay (updated the code. It is much simpler and easier to read now)
How can I overlay QGst::Ui::VideoWidget with another widget?
I am starting to use Qt and I am trying to do an application that uses mouseEvents on a picture QImage. Since I know that QImage is part of QPaintDevice and mouseEvents is part of QWidgets, I don't know how to use both on the same class or even if it would require me to make two independent widgets and overlap them on top of each other. I tried with pixmap, but it is not the best choice since I need pixel manipulation.
Evaluate mouse position/events in a QWidget. Draw the image on that QWidget either in a paintEvent or simply by placing QLabel with an image without margins/borders on that widget.
When the image is not scakled, you can calculate the pixel position having the mouse-position within the image.
I think the simplest way to start is to derive your widget from QLabel and overwrite required mouse events. The offset to the pixel is the contentsRect-position
So I was following this tutorial, https://deadbird.fr/?p=800, to obtain blur behind windows in qt.. Made some changes like request a capture() when a resize event is scheduled and added a timer to update every 200ms the image with QTimer so when for example a window is minimized the background image is updated. So far so good..
But then I tested the timer and I noticed this: https://www.youtube.com/watch?v=WixIShA48jg
As you can see in the sixth second of the video the QGraphicsScene is overlapping the images, even with scene->clear();
The other problem I have is the color. I changed the background color of the dialog to blue but only the borders are blue. I also tried to put the QGraphicsView in a QFrame with transparency and blue color but no luck. Why is that?
You can find the source code in the tutorial site. My changes are visible in the video. The video is also in 720p.
I'm trying to creat a Dicom GUI Toolkit where the user selects some dicom images and the image of first dicom image from the selected ones will be shown. Then the user clicks on the image and the image pops out with bigger image window. In this shown bigger image, the image will consist of a red colored rectangle that contains necessary regions of the Dicom image while the unnecessary region is outside the rectangle. The user should then have the option to change the rectangle by mouse.
Until now, I have been able to show the big dicom image with the rectangle in it using QLabel which is by the following code snippets.
void MainWindow::showBigImage()
{
QPixmap bigimage;
bigimage.load(imageName.c_str());
QPainter painter(&bigimage);
painter.setPen(Qt::red);
QRectF rect(xmin, ymin, xmax, ymax);
painter.drawRect(rect);
QSize bigsize = ui->bigImageLabel->size();
ui->bigImageLabel->setPixmap(bigimage.scaled(bigsize, Qt::IgnoreAspectRatio, Qt::FastTransformation));
ui->bigImageLabel->show();
}
and the big image on the app looks like the following:
Can you please suggest me how I should now make the rectangle editable by the user where the user can set the existing red rectangle as per his or her wish?
I also tried similar thing using QGraphicsView and QGraphicsScene with the following code:
void MainWindow::showBigImage()
{
QGraphicsScene* scene = new QGraphicsScene;
scene->addPixmap(bigimage);
ui->bigImageView->setScene(scene);
ui->bigImageView->show();
}
And this code gives me the following look:
As you can see, I could not fit the image to the boundaries of QGraphicsView, could you suggest me how to do it? Could you also suggest me how to add the red rectangle(that I showed in the example using QLabel) on the QGraphicsView without adding the rectangle on the QPixmap?
In order to get the red selection rectangle, Qt provides the class QRubberBand. The docs state:
The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary.
By subclassing the image object and implementing the mouse handling functions, to create the rubber band on mousePressEvent, update its position on mouseMoveEvent and grab its final rect on mouseReleaseEvent, the QRubberBand will simplify the problem.
If you want the QRubberBand to show all the time, just create it when you display the enlarged image and don't hide it on releasing the mouse button.
As for displaying the image in the QGraphicsView, the code you displayed doesn't set the geometry of the QGraphicsScene and QGraphicsView, so you're seeing a border. If you don't want that, you should set them accordingly. Also note that QGraphicsView has a function fitInView, which you could use, after having retrieved an area from the QRubberBand, in order to zoom into the selected area.
I created a very simple GUI that has a push button and a "Graphics View" widget from Display Widgets. On pushing the button I want a line to be drawn across the "Graphics View" widget. I have changed the name of the "Graphics View" widget to gv by right-clicking the widget in design view and then selecting change objectName. I am not able to understand how should the line be drawn. I read various texts on Qt that provided information about QPainter, PaintEvent etc. But I got more confused.
Kindly help me with this. A small sample code shall be really helpful for me as I am new to Qt.
A QGraphicsView is meant for displaying instances of QGraphicsItem that are managed by a component called QGraphicsScene. In your case, you'd create a QGraphicsLineItem and add it to the scene, or directly create it as an item of the scene by calling the addLine member function of your QGraphicsScene instance.
All drawing will be done by Qt itself, assuming that you did connect your graphics view and scene properly. Be sure to read The Graphics View Framework, which gives you an overview over how these components work.
You will find code examples of how to manage and display a scene using the graphics view framework here: http://doc.trolltech.com/4.6/examples-graphicsview.html
You can paint into a QPainter
Either override the paintevent and draw there
void MyDisplayWidget::paintEvent(QPaintEvent*)
{
QPainter p(this);
p.setPen(Qt::green);
p.drawText(10,10,"hello");
}
Or draw into a QImage and display that
QImage image = QImage(size);
QPainter p(&image);
p.drawText(10,10,"hello");
// draw or save QImage
You can even use the same draw function taking a QPainter * to draw either direct to the screen or to an image.
first you must knew some information about QPainter to have benefit of it.
QPainter provides highly optimized functions to do most of the drawing GUI programs require. It can draw everything from simple graphical primitives (represented by the QPoint, QLine, QRect, QRegion and QPolygon classes) to complex shapes like vector paths .and we use it to draw on paint devices
then render it to view,and we have alot of qpaint devices like : QWidget, QImage, QPixmap, QPicture, QPrinter, and QOpenGLPaintDevice you can use any one of them depending on your requirements then create QGraphic scene and add you paint device as qgraphic scene item to be shown in qgraphic view.
here is simple code:
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
scene=new QGraphicsScene(this); //allocate your scene to your main widget
view=new QGraphicsView(scene,this);//here is your view
pixmap=new QPixmap(QSize(700,700));// paint device
view->resize(700,700);
}
Widget::~Widget()
{
delete ui;
}
void Widget::paintEvent(QPaintEvent *e)
{
painter=new QPainter;// create your painter
painter->begin(pixmap);//add painter to your paint device
painter->fillRect(0,0,300,300,Qt::red);//draw rect
painter->setPen(Qt::yellow);
painter->drawLine(0,0,700,700);//draw line
painter->end();
scene->addPixmap(*pixmap);// add your paint device to your scene
view->show();//then show your view
}