Popup Windows in Qt - qt

I am very new to programming and Qt so please be patient with my ignorance. I have spent two days searching for an answer and I can't figure out where to start.
I'm using Qt 4.8.5 and I would like to create a program that has a mainwindow with a few icons that will open frameless sub windows when clicked.
I've played with the window flags example but none of the options seem to meet my needs... the popup widget is close but I don't want the sub window to disappear when I click on something in the main window. All the other widgets like window and dialog cause the mainwindow to lose focus (not sure this is the right terminology).
Is there a way to make a popup window stay open until the icon is pressed again or use another kind of widget but keep focus on the main window?
I'm sorry if this question is poorly worded.

If I understand correctly what you are asking, you could use setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint); on the widget you wish to use as a popup window. It will give you an always on top frameless window.

Related

Is it possible in QML to add button to the window system menu?

I want to add button to the window main panel (where there are a buttons close-resize-move window).
Please dont propose to draw all window by myself (without using window class).
Is it possible in qml somehow, maybe redefine window slass or draw menu bar over the window menu? Any ideas are wellcome!
I don't think that is possible since the window bar is a native thing and not rendered in the qml flow. There are some flags on qwindow that allow you to modify them a bit but thats as far as it goes. I would suggest digging into your OS-specific API (you didn't specify wich os) to see if it can be done.

Detecting click outside QWidget

My application has non-rectangular popup widgets.
their class defines the following to achieve that transparency:
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_TranslucentBackground, true);
I also use:
this->setWindowFlags(Qt::Popup| Qt::FramelessWindowHint);
The problem is that on windows 7, an automatic "shadow" is being drawn on the bottom and right sides of my window. This is highly undesirable.
So, I tried using Qt::Tool instead of Qt::Popup
this->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
This works visually. No shadow, but now a mouse click outside my widget window will not automatically close/hide it as it would have done with a Qt::Popup.
So, I need one of these two solutions:
A way to have Qt::Popup and get rid of that automatic windows shadow decoration
A way to let the Qt::Tool window a mouse click occurred outside of it.
One note: My application is built for Windows XP and up. I cannot use a Vista/Win7 only runtime DLLs, nor can i have a "Windows XP" and "Vista and up" separate builds.
Any advice will be welcome.
You could manually watch for when the focus changes from your Qt::Tool window. So basically you watch for when the focus goes onto another window of your process or when your application loses focus.
How to detect that my application lost focus in Qt?
Hope that helps.
Finally after realizing that no amount of "SetFocusPolicy" calls will allow me to receive those events for a Qt::Tool window, I've resorted to something else to fix my problem:
I kept the Qt:tool as Qt::Popup caused an undesired shadowing effect, tarnishing my owner draw frame. Removing this style cannot be done in Qt and I didn't want to mess with platform specific conditional code.
I installed an event filter with my Qt::tool window and I began receiving events that assisted me in understanding when other parts of my application were clicked, or if the application itself lost focus to another application. This was what I needed, functionality wise. I could also get an event when users click the non-client areas of the application's main window, such as the windows caption so that I can close it when dragging begins etc.
My solution for Windows 7:
QDialog *d = new QDialog;
d->setStyleSheet("background:transparent;");
d->setAttribute(Qt::WA_DeleteOnClose, true);
d->setAttribute(Qt::WA_TranslucentBackground, true);
#ifdef Q_OS_WIN
d->createWinId();
#endif
d->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);
d->show();
I set my QListView
d->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);
Install eventfilter and used MousePressEvent to hide qlistview widget.
MousePressEvent on list never comes to filter they produce other events which I didn't debug.
So if you want to design auto completer this will be perfect. Tested in Qt5.3.1.

how to get a "lightbox" like behaviour in Qt

I have a Qt project where I'm using QGraphicsView framework, also I have popup windows on the scenes. (QDialogs)
When someone clicks on a certain button a popup window appears, and I'm invoking it with the .exec() method instead of .show() to make it the active one. Also I want to give it a visual effect like lightbox provides for html pages, so it would be obvious for the user too, that the background window won't communicate. Do you know any simple solution to make it work? or is it hard to implement in Qt?
EDIT: I don't know if it's obvious of not, but it's a desktop application, not a web application.
Just create QFrame over necessary area with customized background and transparency. For animation effect you may use QPropertyAnimation + QGraphicEffects and other stuff from qt animation framework.
Now I found another way to accomplish what I wanted. Like this:
QWidget* mytranswidget = new QWidget(mybgwidget);
mytranswidget->setStyleSheet( "background:transparent; background-color:rgba(0,0,0‌​,95)");
mytranswidget->setWindowFlag(Qt::FramelessWindowHint);
mytranswidget->setGeometry(mybgwidget->rect());
mytranswidget->show();
I'm doing it at the beginning of my popup widget's constructor so it's being drawn before draw my popup, so it will be shown in the right order.

QT strange GUI Components: Tabs?

I saw once someone making the GUI in QT and he had something I have never seen until now: They looked like big buttons one after another and when you clicked on them, the buttons below were going down, making space for the dialog or tab. It was like, if you click on the button "Draw", suddenly below the button a tab or a dialog or ??? appeared with all the GUI components (radio buttons, listboxes, ...) that you need for draw. When you clicked on another button, this GUI disappeared to make space for another GUI. Does anybody know what it is?
Qt does support tabs.
They are actually different widgets you can switch from in the same window.
Here you can find an example on how to use then: http://qt-project.org/doc/qt-4.8/declarative-ui-components-tabwidget.html
Inside a tab it's just like a normal widget.

Qt / How can I have subwindows without losing the main window focus?

I have a main window (on MS Windows) and I want to have sub windows or subpanels with free screen movement. I can use dialog and Qt::splashscreen flag, but when I am on these subwindows I lose the focus caption for the main window. Is there any trick to do what I want? (Something like a multi-focus...)
Maybe it is impossible?
I'm not sure what you mean by losing the focus.
When I create an application with multiple windows, this is what I do: in the sub-window widget, I set the parent to the main window, and set the Qt::Tool flag. It has multiple effects: the window manager sees it as one window, and when you focus any window, all the windows raise.
Do you want QMdiArea? Or a focus proxy?
In Qt, all top-level windows are independent, none is the "main". If you want to nominate one as a main window and have it steal focus from the others, then you will have to implement that manually.
Sounds like you just want to have widgets that you can move around freely on a parent widget/window, without invoking the "window focus changed" event between native Windows windows (...).
I'm not sure if there is a ready-made solution for that, but adding some grab/move/resize events to a widget's edges shouldn't be that hard, or?
I'd simply catch mousedown/up events on certain areas (these should probably be widgets of their own with a link to the parent movable widget), and have them resize/move the window when the mouse moves.

Resources