Macos 如何在Mac上编程禁用Qt应用程序的滚动条惯性?
在Qt项目中,我将如何禁用应用程序的OSX滚动条惯性?这样我就可以对惯性等进行自定义控制。这样做:Macos 如何在Mac上编程禁用Qt应用程序的滚动条惯性?,macos,qt,Macos,Qt,在Qt项目中,我将如何禁用应用程序的OSX滚动条惯性?这样我就可以对惯性等进行自定义控制。这样做: project.pro QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = project TEMPLATE = app macx { LIBS += -framework Foundation OBJECTIVE_SOURCES += helper.m } SOURCES +=
project.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = project
TEMPLATE = app
macx {
LIBS += -framework Foundation
OBJECTIVE_SOURCES += helper.m
}
SOURCES += main.cpp
helper.m
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSString.h>
void disableMomentumScroll(void)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"NO" forKey:@"AppleMomentumScrollSupported"];
[defaults registerDefaults:appDefaults];
}
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#ifndef Q_OS_MAC
void disableMomentumScroll() {}
#else
extern "C" { void disableMomentumScroll(); }
#endif
float rnd(float range) { return (qrand() / static_cast<float>(RAND_MAX)) * range; }
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
disableMomentumScroll();
QGraphicsScene s;
for (int n = 0; n < 30; n++) {
s.addRect(rnd(500), rnd(3000), rnd(200), rnd(1000), QPen(Qt::red), QBrush(Qt::gray));
}
QGraphicsView w(&s);
w.show();
return a.exec();
}