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)

有帮助吗?

解决方案

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);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top