Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is it possible to use this plugin in a qml script? #158

Closed
tubbadu opened this issue Jun 23, 2022 · 41 comments · Fixed by #187
Closed

is it possible to use this plugin in a qml script? #158

tubbadu opened this issue Jun 23, 2022 · 41 comments · Fixed by #187
Labels

Comments

@tubbadu
Copy link

tubbadu commented Jun 23, 2022

No description provided.

@pbek pbek added the question label Jun 23, 2022
@pbek
Copy link
Owner

pbek commented Jun 23, 2022

If we are talking about the QMarkdownTextEdit widget, I don't think you can use Qt widgets in QML, but I can be wrong...

@tim-gromeyer
Copy link
Contributor

tim-gromeyer commented Aug 12, 2022

Acording to this Website it would be possible to create a fork and port it to QML. Qt Version 6.2 or abowe required.

@pbek
Copy link
Owner

pbek commented Aug 13, 2022

Hm, but those are no QWidgets, right?

@tim-gromeyer
Copy link
Contributor

We can only try. I'll see what can be done in a few hours.

@pbek
Copy link
Owner

pbek commented Aug 13, 2022

Good luck, have fun. 😁

@tim-gromeyer
Copy link
Contributor

I have created a new repo (I already have a fork). The code works, but I can't figure out how to display in QML a TextEdit object or in this case QMarkdownTextEdit object. Please help. The files here:
example.cpp
example.qml
I have almost no QML experience, because there are far too few examples and tutorials available.

@pbek
Copy link
Owner

pbek commented Aug 13, 2022

Nice 😁

@nuttyartist
Copy link

@tim-gromeyer, did you manage to make this work?? I'm eagerly looking for something like this.

@tim-gromeyer
Copy link
Contributor

No, not really. It was just a black window, but I can give it another try

@nuttyartist
Copy link

No, not really. It was just a black window, but I can give it another try

That would be great. I'm looking to convert our app https://github.com/nuttyartist/notes over to QML and porting this repo would be one of the main things to achieve before continuing.

@pbek
Copy link
Owner

pbek commented Jul 3, 2023

Porting qmarkdowntextedit (which is a widget) to QML? Please keep me posted. 😀

@tim-gromeyer
Copy link
Contributor

@nuttyartist Which Qt version(s) should it be compatible with? I'm planning to use the qt_add_qml_module - CMake command which was introduced with Qt 6.2

@nuttyartist
Copy link

We want to support Qt5 as well. But if it's just the imports that shouldn't be a problem? We can easily add the .qml files into a resource file and load them that way, no?

@tim-gromeyer
Copy link
Contributor

I don't know if the imports are going to make problems yet, I have no experience with QML. The problem I'm facing is, that qt-add-qml-module is needed for building the QML module from the c++ source files.

@nuttyartist
Copy link

Well, any success in this would be appreciated! We can always improve thereafter.

@tim-gromeyer
Copy link
Contributor

Okay, here some updates:

  1. We can support Qt 6.0 - Qt 6.2 by using an alternative to qt-add-qml-module
  2. For Qt5 support, we need to use qmake

I got it working, at least partially:
I managed to compile it and display some text (highlighted).

HOWEVER:

  • It doesn't look like the rest of the QML app (the editor is dark/uses the default QWidget theme and the rest of the app uses some light theme)
  • I could archive editing text yet :/

If you wanna test it, use this tarball (I hope this is allowed (License)). I'M NOT DONE YET and will create a GitHub repo if I'm.

@nuttyartist
Copy link

nuttyartist commented Jul 3, 2023

I'm getting an error during cmake:

CMake Error at /usr/local/lib/cmake/Qt6Qml/Qt6QmlMacros.cmake:126 (message):
  Called without a module version.  Please specify one using the VERSION
  argument.
Call Stack (most recent call first):
  CMakeLists.txt:64 (qt6_add_qml_module)

-- Configuring incomplete, errors occurred!

Although I see that module version is set:

qt_add_qml_module(ExampleProject
    URI ExampleProjectApp
    VERSION 1.0
    QML_FILES example.qml
)

@nuttyartist
Copy link

Nevermind, I added VERSION 1.0 to line 64, but the app seems to crash:

QQmlApplicationEngine failed to load component
qrc:/ExampleProjectApp/example.qml:15:5: MarkdownTextEdit is not a type

@tim-gromeyer
Copy link
Contributor

Hmm... it works for me. Which Qt version are you using? I'm using my system's Qt which is version 6.5.1

@tim-gromeyer
Copy link
Contributor

For the simplicity I created a new branch on my fork. I made some changes which might/should fix this issue. Here the link: https://github.com/tim-gromeyer/qmarkdowntextedit/tree/qml (later, I'll squash the commits and rename the branch)

@nuttyartist
Copy link

I'm using Qt 6.5.0. Using the mentioned repo I get this error:

Undefined symbols for architecture x86_64:
  "qt_static_plugin_QtQmlPlugin()", referenced from:
      StaticQtQmlPluginPluginInstance::StaticQtQmlPluginPluginInstance() in qmlplugin_init.cpp.o
ld: symbol(s) not found for architecture x86_64

Am I missing something?

@tim-gromeyer
Copy link
Contributor

Nope. I created a github actions workflow and there it fails too

@tim-gromeyer
Copy link
Contributor

Oh, great, the build finally works! @nuttyartist would you test it again and See if the "MarkdownTextEdit is not installed" error is fixed?

@nuttyartist
Copy link

Yay! it works! Do you think you can make editing work as well?

@nuttyartist
Copy link

BTW, I'm getting the following runtime errors if helpful:

qt.svg: Cannot open file ':/media/go-top.svg', because: No such file or directory
qt.svg: Cannot open file ':/media/go-top.svg', because: No such file or directory
qt.svg: Cannot open file ':/media/window-close.svg', because: No such file or directory
qt.svg: Cannot open file ':/media/window-close.svg', because: No such file or directory
qt.svg: Cannot open file ':/media/edit-find-replace.svg', because: No such file or directory
qt.svg: Cannot open file ':/media/edit-find-replace.svg', because: No such file or directory
qt.svg: Cannot open file ':/media/go-bottom.svg', because: No such file or directory
qt.svg: Cannot open file ':/media/go-bottom.svg', because: No such file or directory
qt.svg: Cannot open file ':/media/format-text-superscript.svg', because: No such file or directory
qt.svg: Cannot open file ':/media/format-text-superscript.svg', because: No such file or directory
setText
paint
QObject::setParent: Cannot set parent, new parent is in a different thread

@tim-gromeyer
Copy link
Contributor

Yay! it works! Do you think you can make editing work as well?

Hmm... I don't know. It looks like it doesn't receive mouseMove - events which is essential. If this works I can take a look at editing...

@nuttyartist
Copy link

Oh okay, I hope you succeed! We won't be able to incorporate this into our app without editing.

@tim-gromeyer
Copy link
Contributor

Oh okay, I hope you succeed! We won't be able to incorporate this into our app without editing.

Yeah, an editor which doesn't support editing would indeed be a problem 😅️

I figured out, that the mouseMoveEvent only gets called when I press a button on the mouse, e.g. right click.

I'm gonna try to map the hoverMoveEvent to QMarkdoenTextEdit's mouseMoveEvent

@nuttyartist
Copy link

Haha yes. Okay, crossing fingers.

@tim-gromeyer
Copy link
Contributor

@nuttyartist, I have an idea. We could just port the syntax highlighter from QMarkdownTextEdit to QML and apply it to a standard TextEdit, would this be a solution? Or do you need some special functions from QMarkdowntextEdit

@nuttyartist
Copy link

I think that should work as well. How will it be different than QMarkdowntextEdit?

Not quite related question: Qt Quick already supports Markdown rendering but not in a live editor (as a user types) and no syntex highlighting, will it be hard to add live markdown rendering to it?

@tim-gromeyer
Copy link
Contributor

I think that should work as well. How will it be different than QMarkdowntextEdit?

I'm not sure but ai think you will lose features like the search widget, line number area, brackets auto closing, etc.

Not quite related question: Qt Quick already supports Markdown rendering but not in a live editor (as a user types) and no syntex highlighting, will it be hard to add live markdown rendering to it?

AFAIK it support Markdown text, which it renders using md4c.
For live markdown rendering you might take a Look here. As I already said, I have ni experience with QML and I can only guess how hard it'll be

@nuttyartist
Copy link

I'm not sure but ai think you will lose features like the search widget, line number area, brackets auto closing, etc.

Sounds like things our app isn't using already so seems alright.

For live markdown rendering you might take a Look here.

But it isn't live inside the same editor like QMarkdownTextEdit is.

As I already said, I have ni experience with QML and I can only guess how hard it'll be

Well I still think porting the syntax highlighter from QMarkdownTextEdit to QML will be valuable.

@tim-gromeyer
Copy link
Contributor

@nuttyartist I made a nee commit, it should work now. Here a demo video:

Bildschirmaufzeichnung vom 2023-07-04, 16-21-00.webm

@nuttyartist
Copy link

nuttyartist commented Jul 4, 2023

Not sure why I'm getting:

CMake Error at CMakeLists.txt:67 (qt_add_executable):
  Unknown CMake command "qt_add_executable".

EDIT: I was running on Qt 5... testing now again.

@nuttyartist
Copy link

Woohoo! Amazing work, @tim-gromeyer! You made my day.

Is that using the second approach, using just the syntax highlighter from QMarkdownTextEdit?

@tim-gromeyer
Copy link
Contributor

Woohoo! Amazing work, @tim-gromeyer! You made my day.

Thank you! 😁️

Is that using the second approach, using just the syntax highlighter from QMarkdownTextEdit?

Yeah, it is! Works like a charm.

@tim-gromeyer
Copy link
Contributor

@nuttyartist I got it to work with Qt 5.12! And I might upstream these changes here.

@pbek What do you think about the idea (upstreaming)? I'll squash the commits before creating the pull request.

@nuttyartist
Copy link

Awesome!

@pbek
Copy link
Owner

pbek commented Jul 5, 2023

@pbek What do you think about the idea (upstreaming)? I'll squash the commits before creating the pull request.

Sure, that would be great!
As long as QML / QtQuick as dependency is purely optional...

We are talking about develop...tim-gromeyer:qmarkdowntextedit:qml, right?

@tim-gromeyer
Copy link
Contributor

Sure, that would be great! As long as QML / QtQuick as dependency is purely optional...

I made it so that if QtQuick was not found it just doesn't build it.

We are talking about develop...tim-gromeyer:qmarkdowntextedit:qml, right?

Yes, exactly. As you can see there QtQuick is completely optional and I tested it with Qt 5.12 - 6.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants