Results 1 to 4 of 4

Thread: read the position of an another window from a new window

  1. #1
    Join Date
    Jul 2007
    Posts
    166
    Thanks
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default read the position of an another window from a new window

    Hi,
    I have a program in QT 4.3. In that I have a main window and a child window. In that childwindow I have a command button. When I click on that command button, I need to load an another screen. My probs is that, I need to show the new window at the bottom of the cirst fhild window. For that I need to know the current 'x' and 'y' position of the first child window. How can read that position from the new window.
    Please help me....

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: read the position of an another window from a new window

    QWidget::rect() contains the rectangle occupied by each widget. For top-level windows these are in global coordinates.

  3. #3
    Join Date
    Jul 2007
    Posts
    166
    Thanks
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: read the position of an another window from a new window

    Hi,
    With the help of this, QWidget::rect() How can i read the position of another window?
    Can you please give an example for this?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: read the position of an another window from a new window

    You want to align the new windows with the bottom of the childwindow that created it. So when you create the new Window, you read the rect() value from the firstChildWindow that you probably have a pointer to somewhere in your application and then move to the new window to the bottom of the child window with move or setGeometry().


    Qt Code:
    1. //slot creating the new window
    2. void createWindow() {
    3. static QDialog* window = new QDialog;
    4. window->move(frameGeometry().bottomLeft());
    5. window->raise();
    6. window->show();
    7. }
    To copy to clipboard, switch view to plain text mode 
    here is a simple implementation:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class TestDlg : public QDialog
    4. {
    5. Q_OBJECT
    6.  
    7. public:
    8. TestDlg(QWidget* parent = 0) : QDialog(parent)
    9. {
    10. QPushButton* newButton = new QPushButton(tr("Create new Window"));
    11. connect(newButton, SIGNAL(clicked()), this, SLOT(createWindow()));
    12. QLayout* layout = new QVBoxLayout(this);
    13. layout->addWidget(newButton);
    14. }
    15.  
    16. private slots:
    17. void createWindow() {
    18. static QDialog* window = new QDialog;
    19. window->move(frameGeometry().bottomLeft());
    20. window->raise();
    21. window->show();
    22. }
    23. };
    24.  
    25. int main(int argc, char* argv[])
    26. {
    27. QApplication app(argc, argv);
    28. TestDlg dialog;
    29. dialog.show();
    30. return app.exec();
    31. }
    32.  
    33. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    Last edited by momesana; 23rd November 2007 at 12:35.

Similar Threads

  1. Fixing default Window position with move.
    By VireX in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2007, 21:13
  2. Setting the starting position of Main Window
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2006, 12:17
  3. positioning a window at a specific screen position
    By nupul in forum Qt Programming
    Replies: 3
    Last Post: 29th March 2006, 20:21

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.