PDA

View Full Version : read the position of an another window from a new window



sabeesh
23rd November 2007, 09:03
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....

wysota
23rd November 2007, 09:38
QWidget::rect() contains the rectangle occupied by each widget. For top-level windows these are in global coordinates.

sabeesh
23rd November 2007, 09:57
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?

momesana
23rd November 2007, 11:40
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().




//slot creating the new window
void createWindow() {
static QDialog* window = new QDialog;
window->move(frameGeometry().bottomLeft());
window->raise();
window->show();
}

here is a simple implementation:


#include <QtGui>

class TestDlg : public QDialog
{
Q_OBJECT

public:
TestDlg(QWidget* parent = 0) : QDialog(parent)
{
QPushButton* newButton = new QPushButton(tr("Create new Window"));
connect(newButton, SIGNAL(clicked()), this, SLOT(createWindow()));
QLayout* layout = new QVBoxLayout(this);
layout->addWidget(newButton);
}

private slots:
void createWindow() {
static QDialog* window = new QDialog;
window->move(frameGeometry().bottomLeft());
window->raise();
window->show();
}
};

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
TestDlg dialog;
dialog.show();
return app.exec();
}

#include "main.moc"