How to make a window in qt be the main focus - qt

So basically i have a class that inherits from QMainWindow and there's a toolbar action in my mainwindow that calls another small window where the user puts in some info, i want the mainwindow inaccessible i.e you shouldn't be able to click on it or interact with it unless you finish what you're doing on that small window or you close the small window. setWindowFlags(Qt::WindowStaysOnTopHint); only makes the small window be on top, but i can still access the MainWindow.

Looks like all i needed was the setWindowModality(Qt::ApplicationModal); method

Related

Prevent QMainWindow from jumping to foreground after closing QDialog

I'm developing a Qt-based app, using QMainWindow class for the GUI. This app has a built-in server that listens for requests from my Chrome Browser extension, so that I may import information from current web-page into my Qt-app.
So when I press extension's button in the browser, it sends a signal to my Qt-app, which then pops up a QDialog so that I can add some additional information like tags, etc. When I close the QDialog, I expect to return to the browser, but instead my app's main window pops up into foreground if it wasn't minimized (if it was minimized, then it doesn't pop up).
How can I change this behavior, so that I return to my browser after closing QDialog, no matter if the app's main window was minimized or not? If that helps, when creating QDialog, I pass 0 as parent to it.

Qt - Hiding window when the close button is hit

I am trying to implement a terminal in my application.
Currently, class Terminal inherits from QMainWindow, and all of its contents are lost if the close button is triggered. This does not affect the main application though.
I want the contents to stay and be accessible by the rest of the application. How can I achieve that?

Notify QMainWindow toolbar about fullscreen mode switch

In QWindow there is a signal windowStateChanged(Qt::WindowState).
I'm looking for similar signal in QMainWindow. Is it available?
I need it to notify toolbar about fullscreen change, as I have a checkable toolbar button which changes window to fullscreen when user clicks it. However when user changes to fullscreen bypassing the button, it shows invalid state.
QMainWindow inherits from QWidget where you find the ::setWindowState(Qt::WindowStates) method. In its docs, it says:
When the window state changes, the widget receives a changeEvent() of type QEvent::WindowStateChange.
So it seems like you have to override changeEvent() to handle this, I don't think there is a signal.

How to start second QDialog window on side of MainWindow?

I have a application in Qt, and a MainWindow. Now, I also added a helping QDialog which can be hooked up. This QDialog does not influence the programmflow, it just displays information.
But, it always starts on top of the MainWindow :/
SO I would like to start it on the side of the main window, so that it does not hinder the view to the main window?? How?
In my opinion , You should try this,
Use the overload of the QWidget::setParent() function to change the ownership of a QDialog widget, using set as NULL(but It will not share the parent's taskbar entry).
QDialog::show() returns control to the caller immediately, So it will not interfere in mainwindow flow.
Let's say, your application is in the full screen mode. Where then the QDialog should appear? It will be shown on the top and you won't be satisfied again.
If it doesn't influence the flow of the app then you are using it to communicate some sort of message. Can you use different ways? For instance, QStatusBar?
If not, why not to split the mainWindow with QSplitter or similar classes and provide an area where you can post all the info messages?
It sounds you want modaless dialog. In main window, use a slot to create the dialog.
void MainWindow::show_dialog()
{
if ( pDialog== NULL )
pDialog= new XYZ_Dialog(this);
QPoint p = pos();
QSize s = frameSize();
pDialog->setGeometry(p.x()+s.width(), p.y(), s.width()*1/2, s.height());
pDialog->show();
}
What I try to say is if the position of the new dialog bothers you, you set the position and size of it, before showing it.

Shape changing Dialog Box

I was trying to use a shape changing dialog box i.e., when I click on a button the size of the dialog box should become big with the extra details. In order to do that I wrote the following code on button:
QObject::connect(ui->moreButton, SIGNAL(toggled(bool)),
ui->sgroupBox, SLOT(setVisible(bool)));
but there are no changes happening on my dialog box. What should I do in this case.
I had hidden the extra details by placing them in a grid using hide() function. The extra details are getting hidden but the size of widget is not getting changed.
Please help me with a solution
If I understand your question correctly you are trying to resize your QDialog box after clicking on a button in your user interface?
Since a QDialog inherits from a QWidget, you are able to call the QWidget::resize(int width, int height) method.
So now, to make the QDialog grow when you press the button you simply need to connect the toggled(bool) signal to a slot which then calls resize.
ie.
QObject::connect(ui->moreButton, SIGNAL(toggled(bool)), whateverClassManagesYourQDialog, onButtonToggled(bool));
Then implement this slot in your class that manages your QDialog:
ie.
// This is a slot in your class which implements QDialog
whateverClassManagesYourQDialog::onButtonToggled(bool toggledState){
ui->sGroupBox.setVisible(toggledState); // This will show or hide sGroupBox
resize(someIncrement,someIncrement); // This will grow your QDialog
}

Resources