In a Qt project, how would I go about disabling the OS X scrollbar inertia for my application? This is so that I can provide custom control over inertia etc.
问问题
551 次
1 回答
0
这样做:
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];
}
main.cpp
#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();
}
于 2013-08-29T17:38:47.743 回答