Results 1 to 3 of 3

Thread: set a QDialog's initial location

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2018
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default set a QDialog's initial location

    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:
    Qt Code:
    1. class HelpDialog :public QDialog {
    2. (removed the rest)
    3. }
    To copy to clipboard, switch view to plain text mode 

    in helpDialog.cpp
    Qt Code:
    1. HelpDialog::HelpDialog(QWidget *const theParent)
    2. : QDialog(theParent),
    3. ui(new Ui::HelpDialog)
    4. {
    5. ui->setupUi(this);
    6.  
    7. // display the dialog on the right of the current screen.
    8. if (nullptr != MyParent)
    9. {
    10. move( MyParent->parentWidget()->window()->rect().topRight() ); //NOTE: one of various values we've tried here
    11. setWindowFlags(Qt::Window); //ensure the minimize button on the QDialog
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    in code for main application window to bring this up:
    in class init() function
    Qt Code:
    1. myHelp = new HelpDialog(this);
    2. //lamba to handle pressing of help button
    3. const auto ToggleHelp = [this]()
    4. {
    5. const QString HelpText = tr("Some help text goes here");
    6.  
    7. if (isVisible())
    8. {
    9. myHelpDialog->setMessage(HelpText);
    10. myHelpDialog->show(); //use show for nonmodal dialogs
    11. }
    12. };
    13. ( void )connect(footerWidget, &FooterWidget::helpButtonClicked, ToggleHelp);
    14. myHelpDialog->hide();
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 12th February 2018 at 21:48.
    newbie

Similar Threads

  1. initial comboboxes at Qt using Ui
    By citix in forum Newbie
    Replies: 1
    Last Post: 25th November 2013, 18:33
  2. Replies: 9
    Last Post: 25th March 2011, 21:22
  3. QDialog.exec() exiting without calling QDialog::accept()
    By doggrant in forum Qt Programming
    Replies: 3
    Last Post: 2nd February 2011, 11:35
  4. Replies: 2
    Last Post: 16th April 2010, 23:55
  5. How to popup QDialog at specific location?
    By lni in forum Qt Programming
    Replies: 3
    Last Post: 23rd January 2009, 11:46

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.