Hi,
I created a help dialog as a non-modal QDialog that comes up when a button is pressed from our main application. We want it to display just to the right of the application's dialog. However whenever I run it it comes up at the top of the monitor just to the right of center (the application is in the center of the monitor both horizontally and vertically). I have been trying several ways of using "move" but I haven't got it to work. I would appreciate help in the proper way to place it to the right of it's parent. Thanks
in the helpDialog.h:
(removed the rest)
}
class HelpDialog :public QDialog {
(removed the rest)
}
To copy to clipboard, switch view to plain text mode
in helpDialog.cpp
HelpDialog
::HelpDialog(QWidget *const theParent
) ui(new Ui::HelpDialog)
{
ui->setupUi(this);
// display the dialog on the right of the current screen.
if (nullptr != MyParent)
{
move( MyParent->parentWidget()->window()->rect().topRight() ); //NOTE: one of various values we've tried here
setWindowFlags(Qt::Window); //ensure the minimize button on the QDialog
}
}
HelpDialog::HelpDialog(QWidget *const theParent)
: QDialog(theParent),
ui(new Ui::HelpDialog)
{
ui->setupUi(this);
// display the dialog on the right of the current screen.
if (nullptr != MyParent)
{
move( MyParent->parentWidget()->window()->rect().topRight() ); //NOTE: one of various values we've tried here
setWindowFlags(Qt::Window); //ensure the minimize button on the QDialog
}
}
To copy to clipboard, switch view to plain text mode
in code for main application window to bring this up:
in class init() function
myHelp = new HelpDialog(this);
//lamba to handle pressing of help button
const auto ToggleHelp = [this]()
{
const QString HelpText
= tr
("Some help text goes here");
if (isVisible())
{
myHelpDialog->setMessage(HelpText);
myHelpDialog->show(); //use show for nonmodal dialogs
}
};
( void )connect(footerWidget, &FooterWidget::helpButtonClicked, ToggleHelp);
myHelpDialog->hide();
myHelp = new HelpDialog(this);
//lamba to handle pressing of help button
const auto ToggleHelp = [this]()
{
const QString HelpText = tr("Some help text goes here");
if (isVisible())
{
myHelpDialog->setMessage(HelpText);
myHelpDialog->show(); //use show for nonmodal dialogs
}
};
( void )connect(footerWidget, &FooterWidget::helpButtonClicked, ToggleHelp);
myHelpDialog->hide();
To copy to clipboard, switch view to plain text mode
Bookmarks