I want to customize Qt's GUI
Here is the Default Qt OpenCV GUI
I want to place createButton on Menu.
How can I do that?
Below is my code
#include "mainwindow.h"
#include <QApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
void callbackButton2(int state, void* userData){
}
int main(int argc, char *argv[])
{
//QApplication a(argc, argv);
//MainWindow w;
//w.show();
cv::VideoCapture vc(0);
if(!vc.isOpened()) perror("Can't Open WebCam");
const char* winname = "WebCam";
cv::namedWindow(winname,CV_GUI_EXPANDED);
cv::createButton("button6",callbackButton2,NULL,CV_PUSH_BUTTON,1);
for(;;){
cv::Mat frm;
vc>>frm;
if(!frm.empty()) imshow(winname,frm);
if(cv::waitKey(20)==27) break;
}
vc.release();
cv::destroyWindow(winname);
return 0;
// return a.exec();
}
The code above simply opens webcam and display it on the screen. But for my next application, I need to customize gui and place it on to the menu.
BTW I searched through the fllowing link, and I couldn't find how can I customize the GUI. http://docs.opencv.org/2.4/modules/highgui/doc/qt_new_functions.html
I'm not sure about if you can customize the OpenCv Qt windows but you can code your own window and then show the openCv image, using something similiar to this, you can retrive the cv:Mat immage and convert it to a Qimage object then show the object in a Qt graphicsview using a QPixmap.
Related
I want to create a PDF with Qt. This is my code:
#include <QPdfWriter>
#include <QTextDocument>
int main() {
QPdfWriter pdfWriter{R"(C:\TEMP\test.pdf)"};
QTextDocument document;
document.setPlainText("Hello world");
document.print(&pdfWriter);
}
It crashes on the last line with
QPaintDevice: Cannot destroy paint device that is being painted
What did I do wrong?
You didn't create a QApplication. Change the code to
#include <QApplication>
#include <QPdfWriter>
#include <QTextDocument>
int main(int argc, char *argv[]) {
QApplication app{argc, argv};
QPdfWriter pdfWriter{R"(C:\TEMP\test.pdf)"};
QTextDocument document;
document.setPlainText("Hello world");
document.print(&pdfWriter);
}
and it will create the PDF. Running app.exec() is not required.
I wrote some code that show two widgets:
#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
#include <QtGui/QPixmap>
#include <QtWidgets/QWidget>
#include <QtGui/QPalette>
#include <QtGui/QPixmap>
#include <QtGui/QBrush>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QPixmap pix;
pix.load(":/mira.jpg");
QLabel lbl;
lbl.resize(pix.size());
lbl.setPixmap(pix);
lbl.show();
QWidget wgt;
QPixmap pix2;
pix2.load(":/mira.jpg");
QPalette pal;
pal.setBrush(wgt.backgroundRole(), pix);
wgt.setPalette(pal);
wgt.setAutoFillBackground(true);
wgt.resize(pix2.size());
wgt.show();
return app.exec();
}
But I noticed that brightness of the image displayed by this widgets and brightness of the same image displayed by standard macOs Preview.app is slightly differ:
Different brightness evidence
It's not an illusion, I checked it with macOS tool DigitalColorimetor.app and brightness is realy differ, thats true!
Why same images have different brightness in QtWidgets app and standard Preview app? Which image representation is true?
UPD: image opened in (left to right) Preview.app, Qt Creator (Resource View), Google Chrome
Qt does something wrong
I have read a documentation and aswell many sites on website.
Unfortunatly I didn't find answer to my question.
Is there any chance(I believe there is) to fill background outside the popup window? Let me explain: If i have window like of my whole app with resolution 500x500 [px] and I create a popup window 300x300 in the middle - it means I have 200 px in each side "parent-window". Is there any chance (method, flag) to fill background in gray color?
Image: https://imgur.com/Hunev58
Modifying the palette does the job. Here you get a purple background when the MessageBox is shown , and come back to normal once clicked
#include <QApplication>
#include <QMainWindow>
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QMessageBox>
#include <QPalette>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
QVBoxLayout mainLayout;
QLabel foolabel("FooLabel");
QPushButton foobutton("FooButton");
mainLayout.addWidget(&foolabel);
mainLayout.addWidget(&foobutton);
QWidget window;
window.setLayout(&mainLayout);
w.setCentralWidget(&window);
QPalette palette = QApplication::palette(&w);
palette.setColor(QPalette::Inactive,QPalette::Window,QColor(138,43,226));
w.setPalette(palette);
w.show();
QMessageBox box(&w);
box.exec();
return a.exec();
}
I have Qt5 built with submodule QtMultimedia on Debian Jessie 8.2 (BeagleBone Black), I use GStreamer backend (version 0.10.36). I tried to use this simple example to play a video, but it gives me error when trying to play .AVI file: Internal data flow error.
Is the problem in video plugins/codecs I have?
Here is the code:
#include "mainwindow.h"
#include <QApplication>
#include <QMediaPlayer>
#include <QVideoWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMediaPlayer *player = new QMediaPlayer;
QVideoWidget *vw = new QVideoWidget;
player->setVideoOutput(vw);
player->setMedia(QUrl::fromLocalFile("/home/debian/video.avi"));
vw->setGeometry(100, 100, 320, 240);
vw->show();
player->play();
return a.exec();
}
Given below is the code for playing a video file using Qt. Instead of playing the video I want to play a live video stream from an IP Camera. Another approach is to embed the VLC Player in Qt and a link for the project is provided here. The problem is I do not know how to include the player in Qt. So how do I proceed?
#include <QApplication>
#include <QtMultimediaWidgets/QVideoWidget>
#include <QtMultimedia/QMediaPlayer>
#include <QtMultimedia/QMediaPlaylist>
#include <QFile>
#include <QHBoxLayout>
#include "DemoPlayer.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *widget=new QWidget;
widget->resize(400,300);
QMediaPlayer *player=new QMediaPlayer;
QVideoWidget *vw= new QVideoWidget;
QHBoxLayout *layout=new QHBoxLayout;
layout->addWidget(vw);
widget->setLayout(layout);
player->setVideoOutput(vw);
player->setMedia(QUrl::fromLocalFile("C:/Users/Administrator/Desktop/1minute.mp4"));
player->play();
widget->show();
qDebug()<<player->availableMetaData()<<player->currentMedia().canonicalUrl();
return a.exec();
}
follow this code . you can embed a widget inside another widget using a valid window id .
How to show output video of other application in Qt?
you can use the qx11embedwidget and qx11embedwidgetcontainer
QX11EmbedWidget and QX11EmbedContainer