How to Fullscreen mode



  • 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 --&gt; QtImage");
    mainWin->show();    
    int retval = app.exec&#40;&#41;;
    
    cvReleaseCapture(&camera);
    
    return retval;
    

    }

    @



  • 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();
    @



  • 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();@



  • 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]



  • You can have a look at "How to Fullscreen the child widget":http://qt-project.org/forums/viewthread/23852/



  • Image not available:

    !http://nw0.upanh.com/b5.s36.d2/9296d18d72866babf8aad86fd594bef3_55083090.screenshotat20130424000811.png(What is this?)!

    Give code MyCameraWindow class.



  • 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]



  • @diepa9k39

    Did you try with setting the windowFlag and windowState ?



  • I don't understand!
    [quote author="Sam" date="1366866064"]@diepa9k39

    Did you try with setting the windowFlag and windowState ?[/quote]



  • 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);@



  • I want to resize window and frame resize too. Can you help me?



  • 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.



  • Link of Image is working!



  • 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 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.

    QFullScreenFilter.pro:

    @
    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = QFullScreenFilter
    TEMPLATE = app

    SOURCES += main.cpp
    QFullScreenFilter.cpp

    HEADERS +=
    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&#40;&#41;;
    

    }
    @

    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&#41;;
    

    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;
    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.