QDockWidget causes qt crash

I have a Qt version built into ubuntu 11.10. And I'm trying to use a QDockWidget , which actually cannot be a docking station (basically, I just want the window to float. I don't want to just make the presentation top level, because then I will have an OS window window that I don’t want, and if I have to hide it, then the window will not move).

So, I basically create a new Qt Gui project and do not modify any of the files except 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; } 

The problem is that when I switch to moving the widget, the whole program will work. I want to know if I am doing something very bad, or if there is an error in qt.

+6
source share
1 answer

You made the widget floating, but not floating.

 dockWidget->setFeatures( QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable ); 

And you can also have a movable frameless window, controlling the mouse, dragging yourself through mousePressEvent , mouseReleaseEvent and mouseMoveEvent .


How to hide now useless float button

Based on the QDockWidget source code, the "float" button is not displayed if there is a title bar widget:

  dockWidget->setTitleBarWidget(new QLabel("Dock Widget", dockWidget)); 

Or, since it has a name (which is not documented), you can hide it explicitly:

  QAbstractButton * floatButton = dockWidget->findChild<QAbstractButton*>("qt_dockwidget_floatbutton"); if(floatButton) floatButton->hide(); 
+6
source

Source: https://habr.com/ru/post/909960/


All Articles