How to Fullscreen mode
-
wrote on 24 Apr 2013, 02:05 last edited by
Hi all.
I want to capture camera and FullScreen mode. Can you help me? My code
@
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdio.h>
#include <assert.h>
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include "QOpenCVWidget.h"
#include "MyCameraWindow.h"int main(int argc, char **argv) {
CvCapture * camera = cvCaptureFromCAM(0); assert(camera); IplImage * image=cvQueryFrame(camera); assert(image); printf("Image depth=%i\n", image->depth); printf("Image nChannels=%i\n", image->nChannels); QApplication app(argc, argv); MyCameraWindow *mainWin = new MyCameraWindow(camera); mainWin->setWindowTitle("OpenCV --> QtImage"); mainWin->show(); int retval = app.exec(); cvReleaseCapture(&camera); return retval;
}
@
-
wrote on 24 Apr 2013, 04:40 last edited by
If a class MyCameraWindow inherits from QWidget, then to open it in full screen mode, you can use the "showFullScreen":http://qt-project.org/doc/qt-4.8/qwidget.html#showFullScreen method:
@
//mainWin->show();
mainWin->showFullScreen();
@ -
wrote on 24 Apr 2013, 05:23 last edited by
You can also try
@widget = new QWidget();
widget->setAutoFillBackground(true);
widget->setPalette(QPalette(Qt::red));widget->setWindowFlags(widget->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
widget->setWindowState(widget->windowState() | Qt::WindowFullScreen);widget->show();@
-
wrote on 24 Apr 2013, 07:15 last edited by
Thank Konstantin for Reply but If I use showFullScreen() replace show() , the frame not fullscreen only Window is fullscreen
!http://nw0.upanh.com/b5.s36.d2/9296d18d72866babf8aad86fd594bef3_55083090.screenshotat20130424000811.png(pic)!
Can you tell me how to fullscreen also frame , same when I double click Windows Media Player on windows
Thanks!
[quote author="Konstantin Podsvirov" date="1366778456"]If a class MyCameraWindow inherits from QWidget, then to open it in full screen mode, you can use the "showFullScreen":http://qt-project.org/doc/qt-4.8/qwidget.html#showFullScreen method:@
//mainWin->show();
mainWin->showFullScreen();
@
[/quote] -
wrote on 24 Apr 2013, 07:19 last edited by
You can have a look at "How to Fullscreen the child widget":http://qt-project.org/forums/viewthread/23852/
-
wrote on 24 Apr 2013, 11:21 last edited by
Image not available:
!http://nw0.upanh.com/b5.s36.d2/9296d18d72866babf8aad86fd594bef3_55083090.screenshotat20130424000811.png(What is this?)!
Give code MyCameraWindow class.
-
wrote on 25 Apr 2013, 01:45 last edited by
Here is code MyCameraWindow.h
@
#ifndef MYCAMERAWINDOW_H_
#define MYCAMERAWINDOW_H_#include <QWidget>
#include <QVBoxLayout>
#include "QOpenCVWidget.h"
#include <opencv/cv.h>
#include <opencv/highgui.h>class MyCameraWindow : public QWidget
{
Q_OBJECT
private:
QOpenCVWidget *cvwidget;
CvCapture *camera;public: MyCameraWindow(CvCapture *cam, QWidget *parent=0); protected: void timerEvent(QTimerEvent*);
};
#endif /MYCAMERAWINDOW_H_/
@
Here is code MyCameraWindow.cpp
@#include "MyCameraWindow.h"
MyCameraWindow::MyCameraWindow(CvCapture *cam, QWidget *parent) : QWidget(parent) {
camera = cam;
QVBoxLayout *layout = new QVBoxLayout;
cvwidget = new QOpenCVWidget(this);
layout->addWidget(cvwidget);
setLayout(layout);
resize(500, 400);startTimer(100); // 0.1-second timer
}
void MyCameraWindow::timerEvent(QTimerEvent*) {
IplImage *image=cvQueryFrame(camera);
cvwidget->putImage(image);
}@
[quote author="Konstantin Podsvirov" date="1366802481"]Image not available:!http://nw0.upanh.com/b5.s36.d2/9296d18d72866babf8aad86fd594bef3_55083090.screenshotat20130424000811.png(What is this?)!
Give code MyCameraWindow class.[/quote]
-
wrote on 25 Apr 2013, 05:01 last edited by
Did you try with setting the windowFlag and windowState ?
-
wrote on 25 Apr 2013, 07:42 last edited by
I don't understand!
[quote author="Sam" date="1366866064"]@diepa9k39Did you try with setting the windowFlag and windowState ?[/quote]
-
wrote on 25 Apr 2013, 07:53 last edited by
In the above posts I have provide few links that deals with the same issue. Inside the constructor of MyCameraWindow you can set the windowFlag and windowState eg.
@setWindowFlags(widget->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
setWindowState(widget->windowState() | Qt::WindowFullScreen);@
-
wrote on 25 Apr 2013, 08:14 last edited by
I want to resize window and frame resize too. Can you help me?
-
wrote on 25 Apr 2013, 08:19 last edited by
Yes we can help, first of all the images that you attached are not displayed. Kindly update the image links so that it is easy to understand your requirement.
If you are adding your widgets to a layout then the resizing should be handled automatically, you can also set the sizePolicy for your frame.
-
wrote on 25 Apr 2013, 09:46 last edited by
Link of Image is working!
-
wrote on 25 Apr 2013, 10:15 last edited by
Sorry, the images are not visible to me may be the image site is banned at my current location. Can you post the direct link to the images where it is hosted.
-
wrote on 25 Apr 2013, 19:36 last edited by
Wrote a small filter that fits Q[V|H]BoxLayout classes.
Use double click to reveal the element on the full screen.
Use {Esc} to return to the layout.@
QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QFullScreenFilter
TEMPLATE = appSOURCES += main.cpp
QFullScreenFilter.cppHEADERS +=
QFullScreenFilter.hpp
@main.cpp:
@
#include "QFullScreenFilter.hpp"
#include <QApplication>
#include <QLabel>
#include <QVBoxLayout>QLabel* createLabel(const QString &text)
{
QLabel *label = new QLabel(text);
label->setAlignment(Qt::AlignCenter);
label->setFrameStyle(QFrame::Panel | QFrame::Raised);
label->setLineWidth(2);
return label;
}int main(int argc, char *argv[])
{
QApplication app(argc, argv);QWidget widget; QFullScreenFilter *filter = new QFullScreenFilter(&widget); QVBoxLayout *box = new QVBoxLayout(); box->setMargin(20); for (int i = 0; i < 3; i++) { QLabel *label = createLabel(QString("Content %1").arg(i + 1)); label->installEventFilter(filter); box->addWidget(label); } widget.setLayout(box); widget.resize(200, 60 * box->count()); widget.show(); return app.exec();
}
@QFullScreenFilter.hpp:
@
#ifndef QFULLSCREENFILTER_HPP
#define QFULLSCREENFILTER_HPP#include <QObject>
#include <QLayout>
#include <QMap>class QFullScreenFilter : public QObject
{
Q_OBJECT
public:
explicit QFullScreenFilter(QObject *parent = 0);bool eventFilter(QObject *watched, QEvent *event);
private:
bool showFullScreen(QWidget *widget);
bool showNormal(QWidget *widget);struct Attribute { Attribute() : layout(0), index(-1) {} operator bool () { return layout && index >= 0; } QLayout *layout; int index; }; Attribute& getAttribute(QWidget *widget); QMap<QWidget*, Attribute> attributes;
};
#endif // QFULLSCREENFILTER_HPP
@QFullScreenFilter.cpp:
@
#include "QFullScreenFilter.hpp"#include <QWidget>
#include <QBoxLayout>
#include <QMouseEvent>QFullScreenFilter::QFullScreenFilter(QObject *parent) :
QObject(parent)
{
}bool QFullScreenFilter::eventFilter(QObject *watched, QEvent event)
{
if (QWidget widget = qobject_cast<QWidget>(watched))
{
switch (event->type()) {
case QEvent::MouseButtonDblClick:
if (showFullScreen(widget)) return true;
break;
case QEvent::KeyPress:
if (static_cast<QKeyEvent>(event)->key() == Qt::Key_Escape) {
if (showNormal(widget)) return true;
}
break;
default:
break;
}
}
return QObject::eventFilter(watched, event);
}bool QFullScreenFilter::showFullScreen(QWidget *widget)
{
if (Attribute &a = getAttribute(widget)) {
a.layout->removeWidget(widget);
widget->setParent(0);
widget->showFullScreen();
return true;
}
return false;
}bool QFullScreenFilter::showNormal(QWidget *widget)
{
if (Attribute &a = getAttribute(widget)) {
if (QBoxLayout box = qobject_cast<QBoxLayout>(a.layout)) {
box->insertWidget(a.index, widget);
} else {
a.layout->addWidget(widget);
}
return true;
}
return false;
}QFullScreenFilter::Attribute& QFullScreenFilter::getAttribute(QWidget *widget)
{
Attribute& a = attributes[widget];
QWidget *parent = widget ? widget->parentWidget() : 0;
if (!a && parent) {
a.index = (a.layout = parent->layout()) ? a.layout->indexOf(widget) : -1;
}
return a;
}
@
3/15