Reputation: 9014
I create simple QWidget with Qt::Window | Qt::CustomizeWindowHint flags + fixed size (OS: Windows 7). How can I disable dragging of this window by the top border?
Window created without title bar - so it should not be draggable by mouse. Is it bug in Qt (4.8.4)?
Code:
#include <QtGui/QApplication>
#include <QWidget>
int main( int argc, char *argv[] )
{
QApplication a(argc, argv);
QWidget w;
w.setWindowFlags( Qt::Window | Qt::CustomizeWindowHint );
w.setFixedSize( 300, 200 );
w.show();
return a.exec();
}
Screenshot:
UPD: please, do not propose Qt::FramelessWindowHint, because it completery removes border.
The only question is: Why dragging is available only for top border?
Reported as bug: QT-BUG-31144
Upvotes: 0
Views: 4992
Reputation: 19152
You could set your whole widget as disabled.
http://qt-project.org/doc/qt-4.8/qwidget.html#setDisabled
http://qt-project.org/doc/qt-4.8/qwidget.html#enabled-prop
Or you could try making a frameless window.
http://qt-project.org/doc/qt-4.8/widgets-windowflags.html
Or subclass your own QFrame
, and have it consume any mouse events on it.
http://qt-project.org/doc/qt-4.8/qframe.html
http://qt-project.org/doc/qt-4.8/qmouseevent.html
Hope that helps.
To prevent moving specifically in windows you can look into handling:
WM_NCHITTEST
http://msdn.microsoft.com/en-us/magazine/cc301402.aspx
Upvotes: 1
Reputation: 4286
w.setWindowFlags( Qt::Window | Qt::CustomizeWindowHint | Qt::FramelessWindowHint );
does the trick.
Upvotes: 0