Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why doesn't QHotkey work on the widget? #79

Open
xx-hex-xx opened this issue Jan 23, 2023 · 0 comments
Open

Why doesn't QHotkey work on the widget? #79

xx-hex-xx opened this issue Jan 23, 2023 · 0 comments

Comments

@xx-hex-xx
Copy link

Hello! I can't get QHotkey to work on the widget.
If I use the example code from ReadMe in EntryPoint.cpp, the hotkey works but if I use the same code in WMain.cpp it hotkey no longer works.

EntryPoint.cpp --> WORKS

int main(int argc, char* argv[])
{
	QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
	qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
	qputenv("QT_FONT_DPI", "96");

	QApplication qApplication(argc, argv);

	QHotkey hotkey(QKeySequence("Ctrl+Q"), true, &qApplication);
	QObject::connect(&hotkey, &QHotkey::activated, qApp, [&]() { qApp->quit(); });

	WMain wMain;
	wMain.show();

	return qApplication.exec();
}

WMain.cpp --> DOESNT WORK

WMain::WMain(QWidget* parent) : QMainWindow(parent, Qt::FramelessWindowHint)
{
	this->UI_WMain.setupUi(this);

	this->setAttribute(Qt::WA_TranslucentBackground);
	
	this->qGraphicsDropShadowEffect->setBlurRadius(10);
	this->qGraphicsDropShadowEffect->setColor(QColor(0, 0, 0));
	this->qGraphicsDropShadowEffect->setOffset(0);
	this->UI_WMain.widgetMainFrameless->setGraphicsEffect(this->qGraphicsDropShadowEffect);

	QHotkey hotkey(QKeySequence("Ctrl+Q"), true, this);
	QObject::connect(&hotkey, &QHotkey::activated, qApp, [&]() { qApp->quit(); });
}

What am I doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant