gpt4 book ai didi

c++ - 可以在 OSx 中使 QDialog 抖动

转载 作者:行者123 更新时间:2023-11-28 08:04:02 25 4
gpt4 key购买 nike

由于 Qt 在 OSX 下使用 Cocoa,是否可以让模态 QDialog 在用户输入错误密码等情况下摇动?我找不到任何关于它的信息,但在 Mac 上实现它会非常好。

谢谢!

最佳答案

我不知道有什么内置方法可以做到这一点,但您可以自己实现摇晃,如下所示:

标题.h

#include <QtGui>

class ShakyDialog : public QDialog
{
Q_OBJECT

public slots:
void shake()
{
static int numTimesCalled = 0;
numTimesCalled++;

if (numTimesCalled == 9) {
numTimesCalled = 0;
return;
}

vacillate();
QTimer::singleShot(40, this, SLOT(shake()));
}

private:
void vacillate()
{
QPoint offset(10, 0);

move(((shakeSwitch) ? pos() + offset : pos() - offset));
shakeSwitch = !shakeSwitch;
}

bool shakeSwitch;
};

主要.cpp

#include "header.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

ShakyDialog dialog;
QHBoxLayout layout(&dialog);
QPushButton button("Push me.");
layout.addWidget(&button);

QObject::connect(&button, SIGNAL(clicked()), &dialog, SLOT(shake()));

dialog.show();
return app.exec();
}

关于c++ - 可以在 OSx 中使 QDialog 抖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10677324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com