How to enable the menubar in a QUndoView window in Qt? - qt

I use a QUndoStack and I want to show its content using a QUndoView. I create the view as follows:
undoView = new QUndoView(&_undoStack);
undoView->setWindowTitle(tr("Undo Stack"));
undoView->show();
The view is created in a separate window (which is what I want), but that window has a disabled menu bar, so I cannot move it at all, or close it. Is there a way to enable it?

Ok so the issue was that the main window had a window modality of Qt::WindowModality::ApplicationModal which blocks all input to any other top-level window. Simply changing the main window to non-modal with SetWindowModality fixed this.
hide();
setWindowModality(Qt::WindowModality::NonModal);
show();
Alternatively change the modality directly in Qt creator if the main window was created from there.

Related

How to create custom shortcut with Qt?

In my app there is button that when you click on it the main window will be hid then if you type a shortcut the main window will show again.
But the shortcut doesn't work.
Here's my code for the shortcut:
QShortcut *shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_K), this);
QObject::connect(shortcut, &QShortcut::activated, this, &MainWindow::openWindow);
For adding shortcut you set its parent this.
If you close or hide MainWindow means that the shortcut couldn't work because its parent was not called or found.
When you close or hide the window, another screen like your desktop is displayed, so the shortcut does not work.
For example if you write this code :
shortcut = new QShortcut(QKeySequence(tr("Ctrl+k", "Open/Close window")), this);
connect(shortcut, &QShortcut::activated, this, &MainWindow::hide);
when you press Ctrl+k you see that your main window will hide and the shortcut works correctly.
but after that, your desktop will appear and its shortcut will work.

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.

Destroy QWidget returned from Plugin in Qt

My app loads a plugin which creates a window (QWidget), but I can not destroy it when I exit from QMainWindow, obviously because widget returned from plugin is not a child of QMainWindow. The issue is that if I make that window to be a child of mainwindow, I get a window on another window. But I need them both to be separated. I did them separated (but main window has no control over window from plugin), in my case I do not know how to close window from plugin when app quits. How can I achieve that?
Just delete it. If you don't assign it a parent, no other widget has ownership. So you should simply be able to destroy it yourself on exit.

Another Window over QMainWindow in Qt

Can i have another window over main window in Qt , and how can i implement it? I have a plugin which must return another window. I created in plugin a QWidget and set it as centralWidget but my app crashes.Anyway this will not show two windows at same time . Could someone explain how to do that ?
Any new widget created without a parent will show up as a new window. Don't try to reset 'centralWidget' unless you don't actually want the old one anymore.
If all you want is a main window whose contents change, take a look at StackedWidget.

Qt signals and slots working

I have created a Main Window which consists of menu bar with the first menu being "file". Now I am trying to open another window if I click on the "file" menu item. But I am not getting the receiver object of the other window while designing. How can I establish a link?
I am using Qt 4.7
I don't think you can do it by manual linking - this time you will have to write it yourself :P
Simply add a new slot to your window's class, add include for second's window header. Then in slot implementation create new window if necesary and simply call show on it.
Secondly you have to connect file meny to your signal - best is to add connect call in your window constructor AFTER intializing ui.
Also note that if your file option contains actually any submenu, then it's signal will never be emmited, so you need to think about something else in such case.

Resources