我没有成功地试图修改Qt的WindowFlags的例子,以便有一个自定义的小部件。一开始似乎很容易,但我不明白为什么不行。
唯一的是在PreviewWindow
类中,在它的构造函数中:
QVector<QPoint> pts;
pts.push_back(QPoint(0, 10));
pts.push_back(QPoint(36, 10));
pts.push_back(QPoint(36+10, 0));
pts.push_back(QPoint(36+20, 10));
pts.push_back(QPoint(296, 10));
pts.push_back(QPoint(296, 266));
pts.push_back(QPoint(0, 266));
QPolygon p(pts);
setMask(QRegion(pts));
现在,当我用这个加法运行示例时,我没有得到一个好看的窗口。但是,这不是我想要的:那些坐标只指Qt::Tool类型的窗口。
形状作为工具是OK的(只是尝试),但现在我想摆脱窗口框架。不幸的是,整个窗口在绝望中消失了。
我该怎么办?
我不知道为什么会这样,但就是这样。
首先,在设置标志后,一个小部件会消失,但我很放松,因为控制器窗口中的代码在设置标志后称为PreviewWindow::show()
(在ControllerWindow::updatePreview()
)。
void PreviewWindow::setWindowFlags(Qt::WindowFlags flags)
{
QWidget::setWindowFlags(flags);
// This is necessary to show the window again
show();
QString text;
Qt::WindowFlags type = (flags & Qt::WindowType_Mask);
if (type == Qt::Window) {
text = "Qt::Window";
} else if (type == Qt::Dialog) {
text = "Qt::Dialog";
} else if (type == Qt::Sheet) {
text = "Qt::Sheet";
} else if (type == Qt::Drawer) {
text = "Qt::Drawer";
} else if (type == Qt::Popup) {
text = "Qt::Popup";
} else if (type == Qt::Tool) {
text = "Qt::Tool";
} else if (type == Qt::ToolTip) {
text = "Qt::ToolTip";
} else if (type == Qt::SplashScreen) {
text = "Qt::SplashScreen";
}
if (flags & Qt::MSWindowsFixedSizeDialogHint)
text += "n| Qt::MSWindowsFixedSizeDialogHint";
if (flags & Qt::X11BypassWindowManagerHint)
text += "n| Qt::X11BypassWindowManagerHint";
if (flags & Qt::FramelessWindowHint)
text += "n| Qt::FramelessWindowHint";
if (flags & Qt::WindowTitleHint)
text += "n| Qt::WindowTitleHint";
if (flags & Qt::WindowSystemMenuHint)
text += "n| Qt::WindowSystemMenuHint";
if (flags & Qt::WindowMinimizeButtonHint)
text += "n| Qt::WindowMinimizeButtonHint";
if (flags & Qt::WindowMaximizeButtonHint)
text += "n| Qt::WindowMaximizeButtonHint";
if (flags & Qt::WindowCloseButtonHint)
text += "n| Qt::WindowCloseButtonHint";
if (flags & Qt::WindowContextHelpButtonHint)
text += "n| Qt::WindowContextHelpButtonHint";
if (flags & Qt::WindowShadeButtonHint)
text += "n| Qt::WindowShadeButtonHint";
if (flags & Qt::WindowStaysOnTopHint)
text += "n| Qt::WindowStaysOnTopHint";
if (flags & Qt::CustomizeWindowHint)
text += "n| Qt::CustomizeWindowHint";
textEdit->setPlainText(text);
}
一个简单的行,放在一个奇怪的地方。能解释一下为什么会这样吗?