QDockWidget导致Qt崩溃 [英] QDockWidget causes qt to crash
问题描述
我有ubuntu 11.10内置的Qt版本.并尝试使用实际上不能停靠的QDockWidget
(基本上,我只希望窗口浮动.我不想仅使该视图成为顶层视图,因为那样我会在上面放置OS窗口栏,这是我不希望的,如果我将其隐藏,则该窗口将无法移动.)
I Have the version of Qt that is built into ubuntu 11.10. And am trying to use a QDockWidget
that cannot actually dock (basically, I just want a window that floats. I don't want to just make the view be a top level view because then I would have the OS window bar up there, which I don't want, and if I were to hide it, then the window won't be movable).
因此,我基本上创建了一个新的Qt Gui项目,除了mainwindow.cpp
文件以外,不更改任何文件,我将其更改为:
So, I basically make a new Qt Gui project, and don't change any of the files, except for the mainwindow.cpp
file, which I change to:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDockWidget>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QDockWidget *dockWidget = new QDockWidget(this);
// Without window management and attached to mainwindow (central widget)
dockWidget->setFloating( true );
// resize by frame only - not positional moveable
dockWidget->setFeatures( QDockWidget::DockWidgetMovable );
// never dock in mainwindow
dockWidget->setAllowedAreas( Qt::NoDockWidgetArea );
// title
dockWidget->setWindowTitle( "Dock Widget" );
// add contents. etc etc....
dockWidget->show();
}
MainWindow::~MainWindow()
{
delete ui;
}
问题是当我去移动小部件时,整个程序崩溃了.我想知道我是在做错什么,还是qt中只有错误.
The problem is that when I go to move the widget, the whole program crashes. I want to know if I am doing something very wrong, or if there is just a bug in qt.
推荐答案
您使窗口小部件浮动但不可浮动.
You made the widget floating but not floatable.
dockWidget->setFeatures( QDockWidget::DockWidgetMovable |
QDockWidget::DockWidgetFloatable );
通过处理鼠标在mousePressEvent
,mouseReleaseEvent
和mouseMoveEvent
中的拖动,您还可以拥有一个可移动的无框窗口.
And you can also have a movable frameless window, by handling the mouse dragging yourself through mousePressEvent
, mouseReleaseEvent
and mouseMoveEvent
.
基于QDockWidget
源代码,如果有标题栏小部件,则不显示浮动按钮":
Based on QDockWidget
source code, the "float button" is not shown if there is a title bar widget:
dockWidget->setTitleBarWidget(new QLabel("Dock Widget", dockWidget));
或者由于它具有名称(未记录),您可以显式隐藏它:
Or since it has a name (which isn't documented), you can hide it explicitly:
QAbstractButton * floatButton =
dockWidget->findChild<QAbstractButton*>("qt_dockwidget_floatbutton");
if(floatButton)
floatButton->hide();
这篇关于QDockWidget导致Qt崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!