Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, December 2006
Window position within a QWorkspace


Message 1 in thread

Hi, I am trying to report the correct pos() for QMainWindow's being
shown inside a QWorkspace and can't seem to get the child windows to
report anything other than the QWorkspace's pos(). The attached code
shows this behavior. My question is, is this a bug or expected
behavior?

Matt Broadstone
#include <QApplication>
#include <QApplication>
#include <QMainWindow>
#include <QWorkspace>

#include "testwindow.h"

class MainWindow : public QMainWindow
{
public:
    MainWindow()
        : workSpace(0)
    {
        workSpace = new QWorkspace;
        setCentralWidget(workSpace);

        TestWindow *tmp = new TestWindow;
        workSpace->addWindow(tmp);
    }

private:
    QWorkspace *workSpace;
};


int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    MainWindow mainWin;
    mainWin.show();
    return app.exec();
}
#include <QFrame>
#include <QFrame>
#include <QVBoxLayout>
#include <QPushButton>
#include <QDebug>

#include "testwindow.h"

TestWindow::TestWindow()
{
    QFrame *frame = new QFrame;
    QVBoxLayout *layout = new QVBoxLayout(frame);

    QPushButton *button = new QPushButton("Press Me");
    connect(button, SIGNAL(clicked()), this, SLOT(showPos()));
    layout->addWidget(button);

    setCentralWidget(frame);
}

void TestWindow::showPos()
{
    qDebug() << "current position: " << pos();
}

#include "moc_testwindow.cpp"
#ifndef TESTWINDOW_H
#ifndef TESTWINDOW_H
#define TESTWINDOW_H

#include <QMainWindow>
#
class TestWindow : public QMainWindow
{
    Q_OBJECT
public:
    TestWindow();

private slots:
    void showPos();

};


#endif

Message 2 in thread

On 12/19/06, Matt Broadstone <mbroadst@xxxxxxxxx> wrote:
> Hi, I am trying to report the correct pos() for QMainWindow's being
> shown inside a QWorkspace and can't seem to get the child windows to
> report anything other than the QWorkspace's pos(). The attached code
> shows this behavior. My question is, is this a bug or expected
> behavior?
>
> Matt Broadstone

OK, just re-read the docs, and realized that's the geometry within the
QWorkspaceChild window. Oops :)

--
 [ signature omitted ]