0 / 0 / 1
Регистрация: 20.12.2011
Сообщений: 33
1

Vertical scroll in textEdit QML

18.05.2012, 00:00. Показов 8598. Ответов 1
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Добрый день. Необходимо реализовать скролл текста в textEdit.
В документации нашел flickable:
Javascript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Flickable {
              id: flickArea
              x: 0
              y: 0
              width: parent.width; height: parent.height
              anchors.rightMargin: 0
              anchors.bottomMargin: 0
              anchors.leftMargin: 0
              anchors.topMargin: 0
              anchors.fill:parent
              boundsBehavior: Flickable.StopAtBounds
              flickableDirection: Flickable.HorizontalFlick
              interactive: true
                            function ensureVisible(r) {
                  if (contentX >= r.x)
                  contentX = r.x;
                  else if (contentX+width <= r.x+r.width)
                  contentX = r.x+r.width-width;
                  if (contentY >= r.y)
                  contentY = r.y;
                  else if (contentY+height <= r.y+r.height)
                  contentY = r.y+r.height-height;
              }
 
              TextEdit {
                  id: textEdit
                  x: 0
                  y: 0
                  anchors.fill:parent
                  width:parent.width; height:parent.height
                  color:fontColor
                  anchors.rightMargin: 0
                  anchors.bottomMargin: 0
                  anchors.leftMargin: 0
                  anchors.topMargin: 0
                  focus: true
                  wrapMode: TextEdit.Wrap
                  font.pointSize:10
                  onCursorRectangleChanged: flickArea.ensureVisible(cursorRectangle)
                  selectByMouse: true
              }
          }
А хотелось бы реализовать плавный скрол текста, подскажите как это сделать.

Добавлено через 1 час 49 минут
Реализацию нашел в стандартных примерах:
*:\QtSDK\Examples\4.7\declarative\demos\rssnews
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
18.05.2012, 00:00
Ответы с готовыми решениями:

Qml textEdit подсветка
такой вопрос, скажем у меня есть написанный на c++qt редактор кода, очень сырой, и с ужасным...

Большой размер текста в TextEdit qml
Собсно, проблема в следующем: Имеем текстовые файлы, размерами 10 Кб, 100 Кб, 1Мб, обработчик на...

открыть документ рэндомно в textedit QML
Добрый вечер.Имеется в папке 10 файлов с расширением *.html. Как рэндомно, по нажатию на клавишу,...

Подсветка QML элементов QML-ного плагина в QtCreator в случае нахождения QML файлов плагина в ресурсах!
Здравствуйте! Если сделать плагин для QML и подключить его в основном проекте ну как - то так:...

1
2 / 2 / 0
Регистрация: 14.05.2010
Сообщений: 12
26.06.2012, 13:47 2
Вот так будет плавно. =) Поздновато, конечно отвечаю, но все-же подумал, что может кому-то понадобится.
Javascript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Item
{
    width: 200
    height: 800
    Flickable
    {
        id: flick
        anchors.fill: parent
        contentWidth: edit.paintedWidth
        contentHeight: edit.paintedHeight
        interactive: true
        clip: true
 
        function ensureVisible(r) {
            if (contentX >= r.x)
                contentX = r.x;
            else if (contentX+width <= r.x+r.width)
                contentX = r.x+r.width-width;
            if (contentY >= r.y)
                contentY = r.y;
            else if (contentY+height <= r.y+r.height)
                contentY = r.y+r.height-height;
        }
 
        TextEdit
        {
            id: edit
            width: flick.width
            height: flick.height
            focus: true
            wrapMode: TextEdit.Wrap
            selectByMouse: true
            onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
        }
    }
 
    ScrollBar
    {
        scrollArea: textResult
        height: parent.height
        width: 8
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.top: parent.top
        anchors.topMargin: 2
        anchors.bottomMargin: 2
    }
}
А вот скролл
import QtQuick 1.0

Javascript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Item {
    id: container
 
    property variant scrollArea
    property variant orientation: Qt.Vertical
 
    opacity: 0
 
    function position()
    {
        var ny = 0;
        if (container.orientation == Qt.Vertical)
            ny = scrollArea.visibleArea.yPosition * container.height;
        else
            ny = scrollArea.visibleArea.xPosition * container.width;
        if (ny > 2) return ny; else return 2;
    }
 
    function size()
    {
        var nh, ny;
 
        if (container.orientation == Qt.Vertical)
            nh = scrollArea.visibleArea.heightRatio * container.height;
        else
            nh = scrollArea.visibleArea.widthRatio * container.width;
 
        if (container.orientation == Qt.Vertical)
            ny = scrollArea.visibleArea.yPosition * container.height;
        else
            ny = scrollArea.visibleArea.xPosition * container.width;
 
        if (ny > 3) {
            var t;
            if (container.orientation == Qt.Vertical)
                t = Math.ceil(container.height - 3 - ny);
            else
                t = Math.ceil(container.width - 3 - ny);
            if (nh > t) return t; else return nh;
        } else return nh + ny;
    }
 
    Rectangle { anchors.fill: parent; color: "Black"; opacity: 0.3; radius:5;smooth: true}
 
    BorderImage {
        source: "qrc:/image/res/img/scrollbar.png"
        border { left: 1; right: 1; top: 1; bottom: 1 }
        x: container.orientation == Qt.Vertical ? 2 : position()
        width: container.orientation == Qt.Vertical ? container.width - 4 : size()
        y: container.orientation == Qt.Vertical ? position() : 2
        height: container.orientation == Qt.Vertical ? size() : container.height - 4
    }
 
    states: State {
        name: "visible"
        when: container.orientation == Qt.Vertical ? scrollArea.movingVertically : scrollArea.movingHorizontally
        PropertyChanges { target: container; opacity: 1.0 }
    }
 
    transitions: Transition {
        from: "visible"; to: ""
        NumberAnimation { properties: "opacity"; duration: 600 }
    }
}
2
26.06.2012, 13:47
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
26.06.2012, 13:47
Помогаю со студенческими работами здесь

QMl/QT при нажатии на кнопку должен окрыться другой qml файл
Додал anchors Вот что я сделал: import QtQuick 2.5 import QtQuick.Controls 1.4 ...

Как подключить QML-файл в C++ по моде, а также получить ссылки на QML-элементы в C++
Читал в интернете, как подключать QML-файлы. Кто-то использует QQmlView, кто-то...

ListBox Vertical Scroll не работает
Доброго времени суток, форумчане. У меня закралась проблема одна. У меня имеется ListBox, в...

Scroll View+Vertical Layout Group
https://youtu.be/aXPG38a1hOU Как сделать чтобы при любом разрешении показывалась только 8-9...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2023, CyberForum.ru