Refresh score after add Element

• Oct 12, 2015 - 23:08

Hi,

I have a plugin where I add an element to the cursor:


var foo = newElement( Element.STAFF_TEXT );
foo.text = qsTr("foobar");
cursor.add(foo);

The element doesn't get drawn until I do something significant, like Save the score, or rerun the plugin. It doesn't refresh for simpler thnigs, like selecting another element in the score, or playing the score, or changing values in Edit Preferences.

How can I force the flush / refresh of the event queue?

Thanks


Comments

It seems to be an interaction with the QT controls. This code adds two text items to the score. Inside the onRun, the text from makeLabel is displayed immediately. From the buttonOK, however, it will only display after major score refreshes like Save.

import QtQuick 2.0
import QtQuick.Controls 1.0
import MuseScore 1.0

MuseScore {
  id: testGUI
  pluginType: "dialog"
  menuPath: "Plugins.Test Add Element"
  height: 100
  width: 100
  onRun: {
      console.log("start");

      // the requiresScore boolean doesn't appear to work
      if (typeof curScore === 'undefined') {
        console.log("Quitting: no score");
        Qt.quit();
      }

      var cursor = curScore.newCursor();
      cursor.rewind(1); // start of selection
      if (!cursor.segment) {
        console.log("Quitting: no selection");
        Qt.quit();
      }

      makeLabel("one",0); // this displays immediately
  }

  Button {
    id: buttonOK
    text: qsTr("OK")
    width: 60
    height: 40
    anchors.top: testGUI.top
    onClicked: {
      makeLabel("onemore",2); // this does not display till save
      Qt.quit();
    }
  }
   

  function makeLabel(string,yPos) {
      var cursor = curScore.newCursor();
      cursor.rewind(1);
      var myDiag = newElement( Element.STAFF_TEXT );
      myDiag.text = string;
      myDiag.pos.y = yPos;
      cursor.add(myDiag);
  }
}

Do you still have an unanswered question? Please log in first to post your question.