Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 如何在Mac上编程禁用Qt应用程序的滚动条惯性?_Macos_Qt - Fatal编程技术网

Macos 如何在Mac上编程禁用Qt应用程序的滚动条惯性?

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 +=

在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 += 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();
}