Results 1 to 3 of 3

Thread: set a QDialog's initial location

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: set a QDialog's initial location

    I'd try the following:
    0. Remove the moving code from the constructor.
    1. Create the dialog hidden.
    2. Call setGeometry() on it from the parent.
    3. show it.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Feb 2018
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: set a QDialog's initial location

    Thank you - this is the final solution that worked for me

    helpDialog.h - same as above

    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 != theParent)
    9. {
    10. setWindowFlags(Qt::Window); //ensure the minimize button on the QDialog
    11. }
    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. myHelpDialog = 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.  
    11. //place help dialog "top right" corner just inside the top right corner of parent window
    12. QRect rect = myHelpDialog->geometry(); //get current geometry of help window
    13. QRect parentRect = this->geometry(); //get current geometry of this window
    14. rect.moveTo(mapToGlobal(QPoint(parentRect.x() + parentRect.width() - rect.width(), parentRect.y())));
    15.  
    16. myHelpDialog ->setGeometry(rect);
    17.  
    18. myHelpDialog ->show(); //use show for nonmodal dialogs
    19. }
    20. };
    21. ( void )connect(m_footerWidget, &FooterWidget::helpButtonClicked, ToggleHelp);
    22. myHelpDialog ->hide();
    To copy to clipboard, switch view to plain text mode 
    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.