如何在Mac上以编程方式禁用Qt应用程序的滚动条惯性? [英] How to programmatically disable scrollbar inertia for my Qt application on a Mac?

查看:68
本文介绍了如何在Mac上以编程方式禁用Qt应用程序的滚动条惯性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Qt项目中,如何为我的应用程序禁用OS X滚动条惯性?这样我就可以提供对惯性等的自定义控制.

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.

推荐答案

做到这一点:

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

这篇关于如何在Mac上以编程方式禁用Qt应用程序的滚动条惯性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆