0

我正在使用 Qt 和 Magnification API 开发应用程序。我想创建一个具有可变框架的放大镜。我创建了一个 QWidget MagnifierForm:

MagnifierForm::MagnifierForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MagnifierForm)
{
    ui->setupUi(this);
    magFactor = 2.0f;

    hwndHost = reinterpret_cast<HWND>(this->winId());
    setFocusPolicy( Qt::NoFocus );
    if (FALSE == MagInitialize())
    {
        return;
    }

    if (FALSE == SetupMagnifier())
    {
        return;
    }

    magStatus = PARTIAL;

    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(magUpdate()));
    timer->start(10);
}

接下来我创建一个 QFrame MagnifierFrame:

MagnifierFrame::MagnifierFrame(QWidget *parent) :
    QFrame(parent),
    ui(new Ui::MagnifierFrame)
{
    ui->setupUi(this);

    setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::Dialog);
    Qt::WindowFlags flags = windowFlags();
    flags ^= Qt::WindowStaysOnTopHint;

    flags ^= Qt::FramelessWindowHint;
    flags &= Qt::FramelessWindowHint;
    setWindowFlags( flags );

    HWND hwndHost = reinterpret_cast<HWND>(this->winId());
    ::SetWindowLong(hwndHost, GWL_EXSTYLE, WS_EX_TOOLWINDOW );

    ::SetWindowPos(hwndHost, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
    ::SetWindowLong(hwndHost, GWL_STYLE, WS_POPUP);

    magnifierForm = new MagnifierForm(ui->widget);
    ui->widget->setParent(this);
    setAttribute(Qt::WA_TranslucentBackground);
    setAttribute(Qt::WA_TransparentForMouseEvents);
    setAttribute(Qt::WA_PaintOnScreen);
}

问题是放大镜对鼠标事件不透明。请帮忙。

4

0 回答 0