Михаиллл
МихаилллAug. 14, 2019, 9:11 a.m.

Как в QML обновить календарь?

Добрый день.
Так сделал календарь.
После нажатия на число в календаре, меняется в коде расцветка, в которую должны быть окрашенны делегаты календаря. Но видимая расцветка не меняется, календарь не обновляется. Такое обновление не срабатывает:

                    mothGrid1.update()
                    model.update()

Скажите пожалуйста, как обновить календарь?

    MonthGrid {
        id: mothGrid1
        month: 7//Calendar.December
        year: 2019
        x: 23
        y: 154
        width: 340
        height: 355
        //locale: Qt.locale("en_US")

        delegate: Item {
            Rectangle{
                id: rectangleDelegat
                anchors.fill: parent
                //color: AppCore.getVectorDate().includes(model.day + "." + (model.month +1 ) + "." + model.year ) || AppCore.getVectorDate().includes(model.day + "." + 0+(model.month +1 ) + "." + model.year ) ?  "gainsboro" : "white"
                //color: model.date >= Date.fromLocaleString(Qt.locale(), AppCore.getDateOypr1(), "dd.MM.yyyy") && model.date <= Date.fromLocaleString(Qt.locale(), AppCore.getDateOypr2(), "dd.MM.yyyy") ? model.date ===  Date.fromLocaleString(Qt.locale(), AppCore.getDateOypr1(), "dd.MM.yyyy") /*||  model.date == Date.fromLocaleString(Qt.locale(), AppCore.getDateOypr2(), "dd.MM.yyyy")*/ ? "blue" : "gainsboro" : "white"
                border.color: "black"
                border.width: 1
                color: AppCore.getColorRectangleCalendar(Qt.formatDate(model.date,"dd.MM.yyyy"))
            }
            Text {
                id: textDelegat
                //color: AppCore.getVectorDate().includes(model.day + "." + (model.month +1 ) + "." + model.year ) || AppCore.getVectorDate().includes(model.day + "." + 0+(model.month +1 ) + "." + model.year ) ?  "black" : "gainsboro"
                color: AppCore.getColorTextCalendar(Qt.formatDate(model.date,"dd.MM.yyyy"))
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.verticalCenter: parent.verticalCenter
                text: model.day
                font.weight: Font.ExtraLight
            }

            MouseArea{
                anchors.fill: parent
                onClicked: {
                    rectangleDelegat.color = "blue"
                    textDelegat.color = "white"
                    //console.log(model.day + "." + (model.month +1 ) + "." + model.year )
                    //console.log(numberEnterDate)
                    numberEnterDate++
                    if(numberEnterDate === 1 && model.model.month < 10) {AppCore.setDateOypr1(model.day + "." + 0 + (model.month +1 ) + "." + model.year )}
                    if(numberEnterDate === 1 && model.model.month >= 10) {AppCore.setDateOypr1(model.day + "." + (model.month +1 ) + "." + model.year )}
                    if(numberEnterDate >= 2 && model.model.month < 10) {
                        if(date >= Date.fromLocaleString(Qt.locale(), AppCore.getDateOypr1(), "dd.MM.yyyy")){
                        AppCore.setDateOypr2(model.day + "." + 0 + (model.month +1 ) + "." + model.year )
                        }
                        else{
                            AppCore.date2RavnoDate1()
                            AppCore.setDateOypr1(model.day + "." + 0 + (model.month +1 ) + "." + model.year )
                        }
                        loader.source = "FirstWindow.qml"
                    }
                    if(numberEnterDate >= 2 && model.model.month >= 10) {
                        if(date >= Date.fromLocaleString(Qt.locale(), AppCore.getDateOypr1(), "dd.MM.yyyy")){
                            AppCore.setDateOypr2(model.day + "." + (model.month +1 ) + "." + model.year )
                        }
                        else{
                            AppCore.date2RavnoDate1()
                            AppCore.setDateOypr1(model.day + "." + (model.month +1 ) + "." + model.year )
                        }
                        loader.source = "FirstWindow.qml"
                    }
                    mothGrid1.update()
                    model.update()
                }
            }
        }
    }
We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

3
Михаиллл
  • Aug. 14, 2019, 3:03 p.m.
  • The answer was marked as a solution.

Смог сделать только преходом на месяц туда и обратно

                        if (mothGrid1.month > 0) {mothGrid1.month--;}
                        if (mothGrid1.month == 0) {mothGrid1.month = 11; mothGrid1.year--;}
                        if (mothGrid1.month < 11) {mothGrid1.month++;}
                        if (mothGrid1.month == 11) {mothGrid1.month = 0; mothGrid1.year++;}
    Pavel K.
    • Aug. 15, 2019, 3:04 a.m.
    • (edited)

    вот тут

    MouseArea{
         anchors.fill: parent
         onClicked: {
                после изменения цвета 
                вызываем переотрисовку моделт}
    }
    

    у вас модель не явно задана, я пока не пойму как перерисовать ее

    если бы я из плюсов делал(через qmlRegisterType) , было бы что то вроде

    Page {
        id: page
        allowedOrientations: Orientation.All
         model:yourClassModel.createCalendar()
    // some code
         MouseArea{   
             onClicked: {
             меняем цвета ()
            yourClassModel.createCalendar()
        } 
    }
    
      Михаиллл
      • Aug. 15, 2019, 3:19 a.m.

      Плюсы и qml отличаются, с++ логичней

        Comments

        Only authorized users can post comments.
        Please, Log in or Sign up
        AD

        C ++ - Test 004. Pointers, Arrays and Loops

        • Result:50points,
        • Rating points-4
        m

        C ++ - Test 004. Pointers, Arrays and Loops

        • Result:80points,
        • Rating points4
        m

        C ++ - Test 004. Pointers, Arrays and Loops

        • Result:20points,
        • Rating points-10
        Last comments
        i
        innorwallNov. 11, 2024, 10:12 p.m.
        Django - Tutorial 055. How to write auto populate field functionality Freckles because of several brand names retin a, atralin buy generic priligy
        i
        innorwallNov. 11, 2024, 6:23 p.m.
        QML - Tutorial 035. Using enumerations in QML without C ++ priligy cvs 24 Together with antibiotics such as amphotericin B 10, griseofulvin 11 and streptomycin 12, chloramphenicol 9 is in the World Health Organisation s List of Essential Medici…
        i
        innorwallNov. 11, 2024, 3:50 p.m.
        Qt/C++ - Lesson 052. Customization Qt Audio player in the style of AIMP It decreases stress, supports hormone balance, and regulates and increases blood flow to the reproductive organs buy priligy online safe Promising data were reported in a PDX model re…
        i
        innorwallNov. 11, 2024, 2:19 p.m.
        Heap sorting algorithm The role of raloxifene in preventing breast cancer priligy precio
        i
        innorwallNov. 11, 2024, 1:55 p.m.
        PyQt5 - Lesson 006. Work with QTableWidget buy priligy 60 mg 53 have been reported by Javanovic Santa et al
        Now discuss on the forum
        i
        innorwallNov. 11, 2024, 8:56 p.m.
        добавить qlineseries в функции buy priligy senior brother Chu He, whom he had known for many years
        i
        innorwallNov. 11, 2024, 10:55 a.m.
        Всё ещё разбираюсь с кешем. priligy walgreens levitra dulcolax carbs The third ring was found to be made up of ultra relativistic electrons, which are also present in both the outer and inner rings
        9
        9AnonimOct. 25, 2024, 9:10 a.m.
        Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…

        Follow us in social networks