I am learning qt and was trying an example from book, where we have to call pre-made dialogs from main window application.
I already made a dialog which will be used to enter a string(lets call it findDialog), the entered string is passed to a custom slot in QTableWidget to search for the entered string.
I can call the dialog as soon as an action called "find" is triggered, but the problem is that the dialog is shown as frameless.
I am calling the dialog like this, please point out any mistakes.
void MainWindow::find()
{
// Check whether findDialog is already created
if(!finddialog)
{
// create find dialog as a child to main window
finddialog = new findDialog(this);
// Connecting signals and slots
connect(finddialog,SIGNAL(forwardSearch(QString,Qt::CaseSensitivity)),
sheetObject,SLOT(forwardSearch(QString,Qt::CaseSensitivity)));
connect(finddialog,SIGNAL(backwardSearch(QString,Qt::CaseSensitivity)),
sheetObject,SLOT(backwardSearch(QString,Qt::CaseSensitivity)));
}
// Show dialog
finddialog->show();
finddialog->move(200,200);
// Raise if minimised
finddialog->raise();
// Activate it
finddialog->activateWindow();
}
I cannot use exec because, i haven't connected accept() slot in findDialog to anything.
I am also attaching a picture showing the dialog when it has been called. Please tell me the mistake i have done and how to show the dialog with frame.
Got it,
I have to set window flags using setWindowFlags before showing the dialog.
finddialog->setWindowFlags(Qt::Dialog);
to show it as a dialog
or
finddialog->setWindowFlags(Qt::Window);
to show it as a window
You must create finddialog
with appropriate Qt::WindowFlags
. See documentation: Qt::WindowFlags . For example:
finddialog = new findDialog(this, Qt::Window);
Indicates that the widget is a window, usually with a window system frame and a title bar, irrespective of whether the widget has a parent or not. Note that it is not possible to unset this flag if the widget does not have a parent.
Also useful example .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.