Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. JavaScript in QTextEdit?
Forum Updated to NodeBB v4.3 + New Features

JavaScript in QTextEdit?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adamsmith
    wrote on last edited by
    #1

    Is it possible to execute JavaScript in QTextEdit? I'd like to integrate an animation I've done in JavaScript for my website into my QTextEdit project, is that possible?

    JonBJ 1 Reply Last reply
    0
    • W Offline
      W Offline
      wrosecrans
      wrote on last edited by
      #2

      QTextEdit is just a text editor widget. It won't directly have anything to do with running a script. You can type JavaScript into it if you want.

      You can use QScriptEngine to run JavaScript: https://doc.qt.io/qt-5/qtscript-script-helloscript-example.html

      1 Reply Last reply
      4
      • A Offline
        A Offline
        adamsmith
        wrote on last edited by
        #3

        I've tried following the qt-5 documentation but I do not have an int main() but rather test::test(QWidget *parent) : QMainWindow(parent), ui(new Ui::test) so I get error when I try to initialize the app since there is no argv or argc @wrosecrans

        jsulmJ 1 Reply Last reply
        0
        • A adamsmith

          I've tried following the qt-5 documentation but I do not have an int main() but rather test::test(QWidget *parent) : QMainWindow(parent), ui(new Ui::test) so I get error when I try to initialize the app since there is no argv or argc @wrosecrans

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @adamsmith said in JavaScript in QTextEdit?:

          so I get error when I try to initialize the app since there is no argv or argc

          Then adapt the example code to your needs or show your code...

          1 Reply Last reply
          1
          • A adamsmith

            Is it possible to execute JavaScript in QTextEdit? I'd like to integrate an animation I've done in JavaScript for my website into my QTextEdit project, is that possible?

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

            @adamsmith
            I wonder just what you intend to do with your JavaScript in a QTextEdit?

            A QWebEnginePage would allow you JavaScript, see https://doc.qt.io/qt-5/qwebenginepage.html#runJavaScript. I don't know if that is an alternative to a QTextEdit for your use case.

            1 Reply Last reply
            1
            • A Offline
              A Offline
              adamsmith
              wrote on last edited by
              #6

              @jsulm I do not know how to pass arguments into my program in qt since I do not have a main function. I would not write that I get an error unless I do not know how to do it, right? Unnecessary and unhelpful comment.

              @JonB I want to do an animation but that animation requires JavaScript inside my QTextEdit.

              jsulmJ JonBJ 3 Replies Last reply
              0
              • A adamsmith

                @jsulm I do not know how to pass arguments into my program in qt since I do not have a main function. I would not write that I get an error unless I do not know how to do it, right? Unnecessary and unhelpful comment.

                @JonB I want to do an animation but that animation requires JavaScript inside my QTextEdit.

                jsulmJ Online
                jsulmJ Online
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • A adamsmith

                  @jsulm I do not know how to pass arguments into my program in qt since I do not have a main function. I would not write that I get an error unless I do not know how to do it, right? Unnecessary and unhelpful comment.

                  @JonB I want to do an animation but that animation requires JavaScript inside my QTextEdit.

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @adamsmith I'm somehow lost: do you write a test where you use QTextEdit?
                  Because EVERY C or C++ application has exactly one main function.

                  A 1 Reply Last reply
                  0
                  • A adamsmith

                    @jsulm I do not know how to pass arguments into my program in qt since I do not have a main function. I would not write that I get an error unless I do not know how to do it, right? Unnecessary and unhelpful comment.

                    @JonB I want to do an animation but that animation requires JavaScript inside my QTextEdit.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #9

                    @adamsmith

                    @JonB I want to do an animation but that animation requires JavaScript inside my QTextEdit.

                    As I said: QTextEdit may not do what you need since it doesn't support JavaScript. I don't know whether @wrosecrans' answer about using QScriptEngine can be wrapped around a QTextEdit to achieve what you want. But if you want "full" JavaScript like on a web page to do whatever your animation is about you may need to use a QWebEnginePage to achieve.

                    1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @adamsmith I'm somehow lost: do you write a test where you use QTextEdit?
                      Because EVERY C or C++ application has exactly one main function.

                      A Offline
                      A Offline
                      adamsmith
                      wrote on last edited by
                      #10

                      @jsulm I am writing a prototype to see if what I want to achieve is possible in QTextEdit. What I am trying to achieve is an animation when one of the sides of a frame in HTML/CSS is pressed. I have found a way of doing this html/css animation in JavaScript on a prototype website I have already built but I am unable to make this animation happen inside QTextEdit because... well it does not have these types of functions, that is why I want to use JavaScript inside QTextEdit.

                      If somebody is wondering: the "animation" is that when one side of a html frame is pressed the frame extends a certain length. I have to be able to write text aroud (under, on the side, above, etc) of this frame as well as inside the frame, which is possible to do in QTextEdit but not the animation thingy since I can't grab the "side of frame pressed" event in QTextEdit or Qt but I can in JavaScript.

                      @jsulm I do not have a word-for-word main function. I know EVERY C or C++ program has exactly one main function but mine does not have a "int main" or "void main" or "int main(argc ,...)", etc it only has the initialization function that I mentioned above, no "type main (parameters) { ... }"

                      JonBJ 1 Reply Last reply
                      0
                      • A adamsmith

                        @jsulm I am writing a prototype to see if what I want to achieve is possible in QTextEdit. What I am trying to achieve is an animation when one of the sides of a frame in HTML/CSS is pressed. I have found a way of doing this html/css animation in JavaScript on a prototype website I have already built but I am unable to make this animation happen inside QTextEdit because... well it does not have these types of functions, that is why I want to use JavaScript inside QTextEdit.

                        If somebody is wondering: the "animation" is that when one side of a html frame is pressed the frame extends a certain length. I have to be able to write text aroud (under, on the side, above, etc) of this frame as well as inside the frame, which is possible to do in QTextEdit but not the animation thingy since I can't grab the "side of frame pressed" event in QTextEdit or Qt but I can in JavaScript.

                        @jsulm I do not have a word-for-word main function. I know EVERY C or C++ program has exactly one main function but mine does not have a "int main" or "void main" or "int main(argc ,...)", etc it only has the initialization function that I mentioned above, no "type main (parameters) { ... }"

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by JonB
                        #11

                        @adamsmith
                        Last time of saying. QWebEnginePage is a true HTML page and has JavaScript. QTextEdit isn't even HTML, it's for "rich text" as defined by Qt, and uses "HTML-style tags" as its language. It doesn't support JavaScript. Nor for that matter CSS: it supports a "QSS" as defined by Qt.

                        1 Reply Last reply
                        1
                        • A Offline
                          A Offline
                          adamsmith
                          wrote on last edited by
                          #12

                          I'll try QWebEnginePage instead of QTextEdit then! Thanks!

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved