2013-06-11 2 views
0

사용자 정의 위젯을 사용하기 위해 Qt의 WindowFlags 예제를 수정하지 못했습니다. 처음에는 꽤 쉽지만, 왜 작동하지 않는지 알 수는 없습니다.사용자 정의 모양의 QWidgets가 사라짐

예에 추가 생성자에서 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 창 유형을 나타냅니다.

모양은 도구로 사용해도 좋지만 (이제 시도해보십시오), 이제 은 창 프레임을 제거하고 싶습니다. 불행히도, 전체 창은 절망 속에서 사라집니다.

어떻게해야합니까?

답변

0

왜 이런 일이 발생하는지 모르겠지만 여기에 있습니다.

우선 깃발을 설정 한 후 깃발을 넣은 직후에 PreviewWindow::show() 컨트롤러 창에 표시된 코드 (ControllerWindow::updatePreview())가 표시되므로 위젯이 사라집니다.

그러나, 우리는 바로 아래의 PreviewWindow 클래스에 플래그를을 설정 한 후 쇼 를 호출해야합니다

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); 
} 

그래서, 간단한 라인, 이상한 장소에 넣어. 왜 이런 일이 일어날 지에 대한 암시가 있습니까?

관련 문제