I am using Qt 5.6 on Windows (built with the opengl desktop flag, no ANGLE) and I have a widget inheriting QOpenGLWidget as follows:
class SomeWidget: public QOpenGLWidget, protected QOpenGLFunctions
{
...
}
This widget is added in a layout in the main window and has the main window as a parent. The OpenGL stuff displays fine. I want to maximize or make fullscreen that widget and then restore it back to its position / size in the main window. The code looks like that:
onFullscreen()
{
// remove widget from layout
// set widget's parent to NULL
// create a new dialog / layout and add widget to it
// call dialog->showFullScreen
}
onRestore()
{
// set parent to main window
// insert in main window layout
// restore original size
// close dialog
}
I also added in main():
app.setAttribute(Qt::AA_ShareOpenGLContexts); // onFullscreen() crashes if this line is not present
I get a black screen when I go to fullscreen and don't see the red clear color. There is no error message.
Interestingly if I replace dialog->showFullScreen() by dialog->showMaximized() the original rendering disappears and I don't see another dialog.
I have the same approach to display another widget fullscreen that does not derive QOpenGLWidget and it works fine.
Any idea on what is going on and how I could achieve to display the QOpenGLWidget in fullscreen and restore it back in its place in the main window ?
Many thanks !
Related
I've been trying for the last hour to make this work.
The idea es Dock is a class whose base is Gtk::Window, and upon the signal_draw() being emited, the given context should be painted by CairoMM to be transparent.. Instead I see a black window.
Here goes the code:
Dock::Dock() : Gtk::Window()
{
set_decorated(false);
set_default_size(200,200);
set_app_paintable(true);
signal_draw().connect(sigc::mem_fun(*this,&Dock::dibujar));
}
bool Dock::dibujar(const Cairo::RefPtr<Cairo::Context>& contexto)
{
contexto->set_source_rgba(1.0,1.0,1.0,0.0);
contexto->set_operator(Cairo::OPERATOR_SOURCE);
contexto->paint();
return false;
}
Shouldn't it be enough to make the window transparent?
Your draw handler doesn't have access to the information about what else should be painted on the window, so your paint() call paints a transparent layer above what is, I guess by default, a black background.
Luckily there is a method to achieve what you want: Gtk::Widget::set_opacity()
I have a Parent window(derived from CView) which has 3 child windows.
1)Status bar like window.
2)Custom Display window.
3)Custom Dynamic GDI layout window.
All derived from CWnd.
I have created the child windows with WS_CHILD|WS_VISIBLE .
Out of the three child windows 2 windows are fixed on the Parent window.
Third window is a dynamic window which gets created and launched for a click event on status bar window. When a Third window is being displayed it is top of the Display window.
Problem :
When my Dynamic GDI layout is launched and displayed as topmost. Any part of the Display window gets updated then corresponding Dynamic windows screen gets erased.
So for a small region of Display window screen update erases my dynamic windows screen .
Dynamic window gets redrawn when i minimize and restore the entire application window.
PLease let me know how i can avoid my topmost displayed window getting erased when the other sibling window below that gets updated.
Thanks in advance.
I'm opening a modal window from my main window and my interest is to make the background dark so the top window is perfectly visible but the main one looks dark like in the "shade".
You can show some half-transparent widget over the mainwindow and it will create shadow effect.
For example, such widget.
class Overlay : public QWidget
{
public:
Overlay(QWidget *parent) {
setPalette(Qt::transparent);
setAttribute(Qt::WA_TransparentForMouseEvents);
}
protected:
void paintEvent(QPaintEvent *event) {
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setBrush(QBrush(QColor(0,0,0, 150)));
painter.setPen(Qt::NoPen);
painter.drawRect(rect());
}
};
Then create this widget, resize and show:
overlay_.reset(new Overlay(this));
overlay_->resize(size());
overlay_->setVisible(true);
You can play with the shadow color and transperancy by changing brush in paintEvent.
Hope this is the effect you wished.
This is up to the window manager to add such effect.
For example, KWin and Mutter both have their way to handle dialogs. KWin does shade the main window, and I think Mutter does it too with some additional effect.
In Mac OS, modal window are already have special properties to put it in focus on relation of it's patent window.
The way windows handle this is by forcing the focus on the modal I think. But it really is the window manager's job, and up to the user's preference to choose what effect should be active.
I m using Qt5 on linux, I want to display window form fullscreen on second screen (dual monitor)? I tried this code but it doesnt work. Is there any other way?
QRect screenres = QApplication::desktop()->screenGeometry(1/*screenNumber*/);
Widget *secondDisplay = new Widget(); // Use your QWidget
secondDisplay->move(QPoint(screenres.x(), screenres.y()));
secondDisplay->resize(screenres.width(), screenres.height());
You can use QScreen.
QScreen *screen = QGuiApplication::screens()[1]; // specify which screen to use
SecondDisplay secondDisplay = new SecondDisplay(); // your widget
secondDisplay->move(screen->geometry().x(), screen->geometry().y());
secondDisplay->resize(screen->geometry().width(), screen->geometry().height());
secondDisplay->showFullScreen();
One way of doing it in Qt5 is to use QWindow::setScreen to set the screen on which the window should be shown. QWidget has a windowHandle() that returns the pointer to the QWindow.
Here is how to show your widget in the last screen in full-screen mode :
secondDisplay->show();
secondDisplay->windowHandle()->setScreen(qApp->screens().last());
secondDisplay->showFullScreen();
I have a dialog-based MFC C++ app. My dialog displays a number of "pages" (similar to a tab page or property dialog box).
I display each "page" by displaying a Child window over the top of the parent's client area. This works fine on Vista until I then open another window on top of the child.
Vista then seems to draw a thick white rectangular frame within my parent dialog box which paints over the top of my "page" child window(s). If I move another window over the top of this white rectangle, it will repaint the obscured area just fine.
Can somebody please tell me what is going on? Is Vista trying to clear my non-client (frame) area using incorrect coordinates perhaps?
My parent dialog is a skinned class derived from CDialog which handles the painting of my own window titlebar and frames. I've found that if I don't call CDialog::OnNcActivate() within my own OnNcActivate() method, the white rectangle doesn't appear. Of course if I do this then I can't use my child windows.. but OnNcActivate would appear to be related to the problem.
I've figured out the problem.. I shouldn't be calling CDialog::OnNcActivate() - I should have just been returning TRUE instead. All working fine now.