Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, November 1999
Fullscreen mode - HOW?


Message 1 in thread

I've been attempting to get an application to support a fullscreen mode
using reparent/recreate to change the WFlags. Going into fullscreen mode
works, however, when attempting to return to windowed mode the window
disappears (ie is not re-mapped by the window manager). I can't seem to
find any way around this except to destroy the widget  and make a new
one.

Ideas anyone?

A example illustrating the problem is attached.

TIA,

--
 [ signature omitted ] 
#include <stdlib.h>
#include <qimage.h>
#include <qwidget.h>
#include <qpainter.h>
#include "qapp.h"


class fsWidget : public QWidget
{
public:
	fsWidget();
	void toggleFS();

protected:
	virtual void paintEvent(QPaintEvent *e);
	virtual void mousePressEvent(QMouseEvent *e);

private:
	QPixmap img;
	bool fs;
};


fsWidget::fsWidget() : QWidget()
{
	img.load(QString(getenv("QTDIR"))+"/html/qtlogo.png");
	resize(img.size());
	setBackgroundColor(black);
	fs=false;
}

void
fsWidget::paintEvent(QPaintEvent *e)
{
	QPainter painter(this);
	painter.drawPixmap((width()-img.width())/2, (height()-img.height())/2, img);
}

void
fsWidget::toggleFS()
{
	fs=!fs;
	if (fs) { // go full screen
		reparent( 0, WStyle_Customize | WStyle_NoBorder | WType_Popup,
 							QPoint( 0, 0 ), false );
		resize(QApplication::desktop()->size());
    setFocusPolicy( QWidget::StrongFocus );
		qApp->processEvents();
		show();
    setFocus();
	} else { // go back to windowed mode
		close(false);
		reparent( 0, 0,	QPoint(0,0), true );
		show();
	}
}

void
fsWidget::mousePressEvent(QMouseEvent *e)
{
	toggleFS();
}

int main( int argc, char **argv )
{

	QApplication app( argc, argv);

	fsWidget it;	
  app.setMainWidget(&it);
	it.show();

  app.exec();
}

Message 2 in thread

On Tue, 02 Nov 1999, Andrew Richards wrote:
> >%_I've been attempting to get an application to support a fullscreen mode
> using reparent/recreate to change the WFlags. Going into fullscreen mode
> works, however, when attempting to return to windowed mode the window
> disappears (ie is not re-mapped by the window manager). I can't seem to
> find any way around this except to destroy the widget  and make a new
> one.
> 
> Ideas anyone?

Your approach is more or less right. It's a bug in the X11 version of Qt,
thanks for the bugreport.

Please add the following workaround  after the reparent() to become full
screen:
          extraData()->topextra->wmstate = 0;           


Apart from that your example has only three flaws left (that you couldn't test,
since Qt wasn't working): 

   - add resize( img.size() ) when going back to windowed mode. You may want
      to restore the x/y position as well.

   - don't use a WType_Popup, but only WStyle_NoBorder. When a popup closes
      due to a mouse press event, the mouse event is replayed (or use
      mouseReleaseEvent() in your application).

   - don't call close() before going back to windowed mode. Your widget is a
      main widget, if you close it, the application will exit.

Hope that helps,

Matthias

--
 [ signature omitted ] 

Message 3 in thread

You need to put the correct WFlags into your reparent statement coming out of
Ful Screen mode. You need to look up the normal ones and use them, I don't think
you can use just zero.
Tim

____________________Reply Separator____________________
Subject:    Fullscreen mode - HOW? 
Author: Andrew Richards <A.Richards@phys.canterbury.ac.nz>
Date:       11/2/99 11:48 PM

I've been attempting to get an application to support a fullscreen mode
using reparent/recreate to change the WFlags. Going into fullscreen mode
works, however, when attempting to return to windowed mode the window
disappears (ie is not re-mapped by the window manager). I can't seem to
find any way around this except to destroy the widget  and make a new
one.

Ideas anyone?

A example illustrating the problem is attached.

TIA,

--
 [ signature omitted ] 
#include <stdlib.h>
#include <qimage.h>
#include <qwidget.h>
#include <qpainter.h>
#include "qapp.h"


class fsWidget : public QWidget
{
public:
        fsWidget();
        void toggleFS();

protected:
        virtual void paintEvent(QPaintEvent *e);
        virtual void mousePressEvent(QMouseEvent *e);

private:
        QPixmap img;
        bool fs;
};


fsWidget::fsWidget() : QWidget()
{
        img.load(QString(getenv("QTDIR"))+"/html/qtlogo.png");
        resize(img.size());
        setBackgroundColor(black);
        fs=false;
}

void
fsWidget::paintEvent(QPaintEvent *e)
{
        QPainter painter(this);
        painter.drawPixmap((width()-img.width())/2, (height()-img.height())/2, img);
}

void
fsWidget::toggleFS()
{
        fs=!fs;
        if (fs) { // go full screen
                reparent( 0, WStyle_Customize | WStyle_NoBorder | WType_Popup,
                                                         QPoint( 0, 0 ), false );
                resize(QApplication::desktop()->size());
    setFocusPolicy( QWidget::StrongFocus );
                qApp->processEvents();
                show();
    setFocus();
        } else { // go back to windowed mode
                close(false);
                reparent( 0, 0,        QPoint(0,0), true );
                show();
        }
}

void
fsWidget::mousePressEvent(QMouseEvent *e)
{
        toggleFS();
}

int main( int argc, char **argv )
{

        QApplication app( argc, argv);

        fsWidget it;        
  app.setMainWidget(&it);
        it.show();

  app.exec();
}