0

Here is my problem: I created a QDockWidget and put a QGraphicsView in it, while it is floating everything shows up correctly, but if Dock it somewhere, the starting X and Y of my content is on the titlebar of the QDockWidget. Obviously, it should be under:

tilesetWindow = new QDockWidget(tr("Tileset"), this);
tilesetWindow->setMinimumSize(256,256);
tilesetWindow->setFloating(true);
connect(tilesetWindow, SIGNAL(visibilityChanged(bool)), this, SLOT(triggeredTileset()));

tilesetViewer = new QGraphicsView(tilesetWindow);
tilesetViewer->resize(256,256);
tilesetViewer->show();

An image to illustrate this: http://img86.xooimage.com/files/d/7/6/problem-391a96a.png

I've tried to put the QGraphicsView in a container and then in the QDockWidget but had the same result as above. it's the only place where I write code for the QDockWidget.

How can I make it start at the right place when it is Docked?

Edit:

I tried in a new QtProject and made a QDockWidget with a QTextBrowser in it and had the same bug:

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QDockWidget *dock = new QDockWidget(this, 0);
    dock->setFloating(true);

    QTextBrowser *t = new QTextBrowser(dock);
    t->show();
}

I'm missing something I think...

Qt Creator 2.4.1 Based on Qt 4.7.4 (32 bit)

user1236892
  • 17
  • 1
  • 1
  • 5
  • This kind of problem tends to occur when a widget isn't parented properly. Is `tilesetWindow` an immediate child of the `QMainWindow`? – D K Oct 30 '12 at 00:30
  • `this` in the code, is the `QMainWindow`, so yes. I tried: `this->addDockWidget(Qt::LeftDockWidgetArea, tilesetWindow, Qt::Horizontal);` But had the same result. – user1236892 Oct 30 '12 at 00:47
  • Hmm. I can't help you further then, but if you give your Qt version, it might help others. – D K Oct 30 '12 at 00:51

1 Answers1

0

After setting the QDockWidget as the Parent, you also need to set the QDockWidget's Widget as the QGraphicsView, or any other you want.

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

QDockWidget *dock = new QDockWidget(this, 0);
dock->setFloating(true);

QTextBrowser *t = new QTextBrowser(dock);
dock->setWidget(t);
}
user1236892
  • 17
  • 1
  • 1
  • 5