qt creator to give control from one window to another - qt

how to give control from one window to another by a pushbutton click

Both windows must be part of the same application. Connect the QPushButton clicked signal to a slot on the other window in which activateWindow() is called.

Related

Qt Widgets do not get showEvent() when tabbed in dock area of QMainWindow

In QMainWindow, when few widgets are tabbed together in dock area, how can I detect when a tab has been toggled by user? It is not a problem when I have an instance of QTabWidget created by myself and can attach a handler to currentChanged(), but what's about this case when the main window internally performs docking/tabifying operations? It normally would be showEvent() triggered but by some reason it doesn't work when tabs are switched. Also, a widget, not on active tab, has it's visibility state turned ON (isVisible() returns true) which is strange.
I found the answer. It is QMainWindow::tabifiedDockWidgetActivated() which is signaled when a tab on a docked widget changes. It was added in Qt 5.8. Without it there is no way.

How can i change QStackWidget page index with button in Qt Designer?

I am currently working in Qt Designer and i am trying to make button change the index of QStackWidget with click signal.
I entered signal editor mode and connected Button to QStackWidget, This is what i got:
As you see in the picture, setCurrentIndex(int) is grayed out, If i choose any signal from QPushButton, there is nothing associated with changing page.
Sorted Question:
How can i change the page in QStackedWidget using a button? (In Qt Designer).
That is not possible directly with Qt Designer, because QButton click signal doesn't send any index or argument, and setCurrentIndex(int) need an argument to chose change the index.
You have to do it using signal/slot in C++ code, or use an other widget like QSpinBox which emit a signal with an integer argument.

What SIGNAL is emitted in Qt when pressing the "X" on the top right corner to terminate the Window?

Which SIGNAL is emitted, when pressing the "X" in the top right corner of a Qt Window application?
I have a second QDialog widget beside my MainWindow in my Qt application. And I would like to intercept the press on the "X" in my second QDialog, how?
The QCloseEvent class contains parameters that describe a close event. Close events are sent to widgets that the user wants to close, usually by choosing "Close" from the window menu, or by clicking the X title bar button. They are also sent when you call QWidget::close() to close a widget programmatically.
To ignore it you can call ignore() method:
void YourDialog::closeEvent(QCloseEvent* iEvent)
{
// ignore close event
iEvent->ignore();
}
There is no signal for that, you need to reimplement QWidget::closeEvent() or install an event filter filtering for QCloseEvents.

Qt Calling Another Ui

I have created 2 *.ui using Qt Designer in my project, where one is the main screen and another one is a dialog widget. The dialog widget is called by one of the functions in main screen.
How can I connect the function in my main window to call the dialog widget?
e.g. If I click on [About > Author] in my main window's menu, I should be able to call the dialog widget.
Any help will be appreciated.
Thanks.
It depends on where you keep your dialog pointer. For example, you can create some signal on your main window and connect it with dialog show() slot(or exec() if you need it to be modal).
Or if you keep your dialog pointer in the main windows then you can just use it with show/exec method directly.
As to About->Author menu: for that you should create QAction and add it to the menu. And QAction has triggered() signal which you can connect to exec/show slot of the dialog.

qt create dialog

I've made my first qt window. Now I'd like to make my first dialog, using qt. I have just finished creating the dialog, which is basically made of a QDialogButtonBox, and now I'd like to connect it to the window. I have two beginner's questions:
How can I retrieve how the dialog was closed (ok pressed or cancel pressed) from the window.cpp, which creates a new dialog, and then calls dialog->show() ?
Where and how to destroy the dialog pointer ?
If you use dialog->show() then I assume it's non-modal dialog.
If you have created QDialogButtonBox and connected its signals with accept() and reject() slots of your dialog as documentation shows, then your dialog will emit finished(int) and additionally accepted() or rejected() signals by which you can determine how it was closed.
If you need more customized behavior, then you can reimplement closeEvent(QCloseEvent *event) or create your own singnals.
If you need to delete your dialog you can use setAttribute(Qt::WA_DeleteOnClose, true);, which will delete instance on close.
you can use one flag, and signal and slot.
when put OK flag=1 , and when put cancel then flag=-1; and then use signal.
in in the window.h write code how to handle that flags with 1 simple slot.
for destroying the pointer you can use signal and slot in your Dialog and tell when user push
Ok, or Cancel , or exit (up- right (red cross)) go to slot in call the Destructer of dialog
and also you that you better set parent of dialog to window.
First Question:
When you want to show the dialog,just construct it,using myDialog *d = new myDialog(this)(the this pointer will make sure that you havn't to delete the pointer you created 'cause Qt will handle this if you specified the dialog's parent). And use d->exec() if you need a modal dialog, or d->show() to make it non-modal;
Second Question:
Once your specified the dialog's parent object, all u need is just use it and leave alone the memory managent,Qt will do this for you. Also you can use d->setAttribute(Qt::WA_DeleteOnClose,true) to make it destroy itself when it is closed.
Remember to link the QDialogButtonBox to your dialog's actions.

Resources