I would like to know if there is any class that I can work with that accepts mp4, because the multimedia class is not active in qt6.3.
I'm trying to load mp4 files in the background, but I didn't find classes in qt(6.3)
You can use QMediaPlayer for this.
player = new QMediaPlayer;
player->setSource(QUrl::fromLocalFile("/Users/lpapp/Music/song.mp4"));
player->play();
For video rendering, you can even use the QVideoWidget class:
videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
videoWidget->show();
Related
I am trying to get a video to fill a QGraphicsView. While I do get playback it only fills a portion of the view like so:
Here is the code to play the video in the graphics view:
QMediaPlayer* player;
player = new QMediaPlayer(this);
QGraphicsVideoItem *item = new QGraphicsVideoItem;
player->setVideoOutput(item);
ui->graphicsView->setScene(new QGraphicsScene());
ui->graphicsView->scene()->addItem(item);
ui->graphicsView->show();
player->setMedia(QUrl("http://commondatastorage.googleapis.com/gtv-videos-
bucket/sample/BigBuckBunny.mp4"));
player->play();
What I would like is for the video to fill the whole window. The graphics view itself fills the window. I have tried resizing the video with ui->graphicsView->fitinView(item) as well as changing some scene parameters but I have not seen any difference.
I have a problem, i'm developing a graphical program under Windows, there are few QGraphicsScene and one QGraphicsView that it is possible to change the Scenes in runtime with a lot of graphics items, the problem is when I use Qwidget viewport everything works but when I switch to OpenGL viewport when I change the scene the content of previous scene still appear on the QGraphicsView and the contents of new Scene appear too.
what is the problem ? is it the changing Scenes method best solution or should I change the method ?
here is the code to setup View
m_viewPort = new QOpenGLWidget (this);
QSurfaceFormat format;
format.setProfile(QSurfaceFormat::CoreProfile);
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setSamples(4);
m_viewPort->setFormat(format);
ui->gV->setViewport(m_viewPort);
ui->gV->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
//ui->gV->setCacheMode(QGraphicsView::CacheBackground);
ui->gV->setRenderHints(QPainter::Antialiasing| QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform| QPainter::TextAntialiasing);
ui->gV->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->gV->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
ui->gV->setTransformationAnchor(QGraphicsView::NoAnchor);
ui->gV->setAutoFillBackground(false);
ui->gV->setAttribute(Qt::WA_OpaquePaintEvent, true);
ui->gV->setAttribute(Qt::WA_NoSystemBackground, true);
resize(boardBaseSize);
here is code to set the new scene to the view
void GlScreenBoard::setShowScene(QGraphicsScene *scene, QString programName)
{
scene->setSceneRect(boardSceneRectBase);
ui->gV->setScene(scene);
}
another problem is when I set Graphics view CacheMode to CacheBackground the OpenGL viewport disables !! and the painter in QGraphicsScene returns to Raster !
I'm working with JavaFx and i'm looking for an equivalent of the AWT BufferedImage. I saw that I can used SwingFXUtils to used an awt BufferedImage with JavaFx but I don't want to used awt.
In fact I'm looking for a structure to display a table of pixel witch is associated to a ColorModel.
Does anybody know some equivalent with JavaFx ?
Thanks a lot.
The closest you get to a BufferedImage in JavaFX is javafx.scene.image.WritableImage. It is a subclass of javafx.scene.image.Image, and was introduced in JavaFX 2.2.
Depending on your use case, javafx.scene.canvas.Canvas and javafx.scene.canvas.GraphicsContext (similar to a Graphics2D Java2D) might be a better fit.
To paint on a Canvas node and get the contents in a WritableImage, use (adapted from the Canvas JavaDoc):
// Create canvas
Canvas canvas = new Canvas(250, 250);
GraphicsContext gc = canvas.getGraphicsContext2D();
// Paint on it
gc.setFill(Color.BLUE);
gc.fillRect(75, 75, 100, 100);
// NOTE: The canvas must be part of a Scene for the following to work properly, omitted for brevity
// Obtain a snapshot of the canvas
WritableImage image = canvas.snapshot(null, null);
See Working with Canvas from he JavaFX tutorials for more information.
Im trying to make an application that takes live image recorded by camera and shows it on screen using Qt GUI. The camera driver and api provides me with functionality that refreshes the memory block showed by pointer.
The problem is my image won't refresh inside Qlabel made with Qimage (code below)
QImage myImage(raw_image_data_pointer, 768, 576, QImage::Format_RGB32 );
QLabel myLabel;
myLabel.setPixmap(QPixmap::fromImage(myImage));
myLabel.show();
How can i get my QLabel to be refreshed?
The problem is that you create the label widget with a static image inside. The containing image is not "connected" to your camera anymore, but is just a copy of a frame of your video stream. In order to make QLabel to update itself, you have to constantly replace the containing image with new one. For example, you can set up a timer for that:
MyClass:MyClass()
{
QTimer *timer = new QTimer;
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(10); // Defines how often update the label.
myLabel = new QLabel;
[..]
}
// Slot
MyClass::update()
{
QImage myImage(raw_image_data_pointer, 768, 576, QImage::Format_RGB32 );
myLabel.setPixmap(QPixmap::fromImage(myImage));
}
I have an exisiting Graph displayed as QWidget which I can already save to a bitmap using grab():
QPixmap image = grab();
Is there a Possibility to save that widget also to .svg?
Thanks!
QSvgGenerator generator;
generator.setFileName(path);
generator.setSize(widget->size());
generator.setViewBox(widget->rect());
generator.setTitle(tr("Your title"));
generator.setDescription(tr("some desscription"));
widget->render(&generator);