Ярлыки

вторник, 9 октября 2018 г.

QML - в переводе добавить перенос строки

Если необходимо в ts файле перевода добавить перенос строки, то \n обычно не срабатывает. Тогда необходимо при редактировании ts файла нажать Enter.
Additional info here.

четверг, 27 сентября 2018 г.

QML - set default font

If you want set font for all items in ApplicationWindow. In main.cpp you must configure QFont and set it to QApplication.

    QApplication app(argc, argv);
    QFont font;
    font.setPixelSize(20);
    app.setFont(font);
}

Additional info here.

QtCreator highlight current line

If you want highlight current line in editor
Main menu: Tools > Options > Text Editor > Display > Highlight current line

QML - SystemPalette visible in all files

If you want use system colors create static variable in special singleton object.

// Style.qml
pragma Singleton
import QtQuick 2.11
QtObject {
     property SystemPalette palette: SystemPalette { colorGroup: SystemPalette.Active }
}

And then use it.

import QtQuick 2.0
Rectangle {
    color: Style.palette.highlight
}

Additional info here.

четверг, 30 августа 2018 г.

QtCreator - missing main menu

To open settings window in QtCreator
  • 1. Switch to debug mode
  • 2. Right click on 'Name|Value|Type' area
  • 3. In menu choose 'Configure debugger'
  • 4. Configure hot keys in 'Envioronment' tab

Additional info here.

четверг, 16 августа 2018 г.

Qt - check QObject derived class type

Example of using DelegateModel for hierarchical tree of data.

Tag* tag = new Tag();
Tag* tag_cast = qobject_cast<QObject*>(tag);
if(tag_cast) qDebug() << "Cool!";
else qDebug() << "oh..";

Additional info here and here.

понедельник, 16 июля 2018 г.

QML - nested ListView

Example of using DelegateModel for hierarchical tree of data.

import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQml.Models 2.3

ListView {
    id: view
    anchors.fill: parent
    focus: true
    highlight: Rectangle {
        width: view.width; height: view.currentItem.height
        y: view.currentItem.y
        color: "blue"
    }
    highlightFollowsCurrentItem: true
    model: DelegateModel {
        model: catalogTreeModel //common QAbstractItemModel model
        delegate: Item {
            width: view.width; height: colDlg.height
            Column {
                id: colDlg
                width: view.width
                height: itemDlg.height + subView.height
                Item {
                    id: itemDlg
                    width: view.width
                    height: childrenRect.height
                    Text { text: session }
                    MouseArea {
                        anchors.fill: parent
                        propagateComposedEvents: true
                        onClicked: {
                            view.currentIndex = index
                            subView.shown = !subView.shown
                        } //onClicked:
                    } //MouseArea
                } //Item
                ListView { // nested ListView
                    id: subView
                    property int parentIndex: index
                    property bool isParrentSelected: view.currentIndex===index
                    property bool shown: false
                    width: view.width; height: shown ? /*_rowsCount * 25*/ subView.count * 25 : 0
                    visible: shown
                    enabled: shown
                    highlight: Rectangle {
                        id: subHighlight
                        visible: subView.isParrentSelected
                        focus: true
                        color: "red"
                    } //highlight:
                    model: DelegateModel {
                        model: catalogTreeModel
                        rootIndex: view.model.modelIndex(subView.parentIndex) // change root index for nested branch
                        delegate: Item {
                            width: view.width; height: txt.contentHeight
                            Text { id: txt; text: session }
                            MouseArea {
                                anchors.fill: parent
                                z: 1
                                hoverEnabled: true
                                propagateComposedEvents: true
                                onClicked: {
                                    subView.currentIndex = index
                                    view.currentIndex = subView.parentIndex
                                } //onClicked:
                            } //MouseArea
                        } //delegate:
                    } //model
                } //ListView
            } //Column
        } //delegate:
    } //model:
} //ListView

Additional info here.