Page 2 of 6 FirstFirst 1234 ... LastLast
Results 21 to 40 of 113

Thread: How to set QWebEngineView on QQuickView

  1. #21
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to set QWebEngineView on QQuickView

    When I have the webengineview in QML, is it possible for SetHtml(). This is because the the html pages are in local storage and in encrypted format.
    In the code, I will decrypt and set the page using SetHtml().

    Otherwise, is it possible possible to superimpose the ReaderToolBar.qml over WebEngineView.cpp which will make the setHtml() easier.

  2. #22
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to set QWebEngineView on QQuickView

    Quote Originally Posted by ejoshva View Post
    When I have the webengineview in QML, is it possible for SetHtml(). This is because the the html pages are in local storage and in encrypted format.
    In the code, I will decrypt and set the page using SetHtml().

    Otherwise, is it possible possible to superimpose the ReaderToolBar.qml over WebEngineView.cpp which will make the setHtml() easier.
    WebEngineView has a url method that takes the url of a resource to be loaded. The resource is loaded via QNetworkAccessManager bound to the QML engine. You can control that engine and there you can decrypt the data.

    Remember that QWebEngineView is a widget, not a Qt Quick element, you cannot simply put it on a Qt Quick scene.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #23
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to set QWebEngineView on QQuickView

    @wysota , I will try to implement just as u suggested

    Meanwhile, I tried something like the below, here only the 2nd widget added (weview) alone is displayed. When I comment out, lay->addWidget(weView); ReaderToolBar is displayed.
    Qt Code:
    1. WebEngineView *weView = new WebEngineView();
    2. weView->setGeometry(55,0,1000,750);
    3. weView->show();
    4. QQuickView view;
    5. view.setSource(QUrl("qrc:/ReaderToolBar.qml"));
    6. view.setGeometry(0,0,1200,50);
    7. view.show();
    8. QVBoxLayout *lay = new QVBoxLayout();
    9. lay->addWidget(QWidget::createWindowContainer(&view));
    10. lay->addWidget(weView);
    11. QWidget *wid = new QWidget();
    12. wid->setLayout(lay);
    13. wid->resize(1200,800);
    14. wid->show();
    To copy to clipboard, switch view to plain text mode 

    What I am doing wrong here.

  4. #24
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to set QWebEngineView on QQuickView

    Quote Originally Posted by anda_skoa View Post
    How about you start with the basic setup and then extend it once it works.

    So on C++ side just
    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. QQuickView view;
    6. view.setSource(QUrl("qrc:/main.qml");
    7. view.show();
    8.  
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    And you can set your toolbar directly as the ApplicationWindow's toolBar property
    Qt Code:
    1. ApplicationWindow {
    2. toolBar: ReaderToolBar { ... }
    3. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _
    I am trying to implement this but I am getting error as
    component errors : (qrc:/Main.qml:18:13: Invalid attached object assignment)

    Qt Code:
    1. import QtQuick 2.4
    2. import QtQuick.Controls 1.3
    3. import QtWebEngine 1.0
    4.  
    5.  
    6. ApplicationWindow {
    7. title: qsTr("diacritech")
    8. width: 1200
    9. height: 800
    10. visible: true
    11.  
    12. WebEngineView {
    13. id: currentwebview
    14. objectName: "webView"
    15. url: "http://www.google.co.in"
    16. anchors.fill: parent
    17.  
    18. ToolBar :readTool
    19. }
    20. function showPage(content,baseUrl)
    21. {
    22. //console.log(content);
    23. //console.log(baseUrl)
    24. currentwebview.loadHtml(content,baseUrl)
    25. }
    26. ReaderToolBar {
    27. width: parent.width
    28. height: 50
    29. id : readTool
    30. // anchors: { left: parent.left; right: parent.right; top: parent.top }
    31.  
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 

  5. #25
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to set QWebEngineView on QQuickView

    Line 18 doesn't make sense. Compare anda_skoa's code and yours. And look up functionality that you use in API docs instead of blindly trying things hoping it would work.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #26
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to set QWebEngineView on QQuickView

    Quote Originally Posted by ejoshva View Post
    This is because the the html pages are in local storage and in encrypted format.
    In the code, I will decrypt and set the page using SetHtml().
    Wouldn't it be a lot easier to just write the content to a temporary file and pass the URL to that to the view?

    Cheers,
    _

  7. #27
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to set QWebEngineView on QQuickView

    Quote Originally Posted by anda_skoa View Post
    Wouldn't it be a lot easier to just write the content to a temporary file and pass the URL to that to the view?

    Cheers,
    _
    if it's one or two pages, then its fine I guess. But I will have whole book say 500 pages to show. If I am showing only one page at a time then not a problem. I have reflow layout means , I will just keep scrolling and pages will be shown.

    currently I have written the qml like below, it's displaying the tool bar over the webengineview and next /previous buttons are also displayed.
    The issue now is that the click events are not detected for the next/previous or elements on tool bar. Is there something, I should include to capture the click events.

    Qt Code:
    1. ApplicationWindow {
    2. title: qsTr("diacritech")
    3. width: 1200
    4. height: 800
    5. visible: true
    6.  
    7. WebEngineView {
    8. id: currentwebview
    9. objectName: "webView"
    10. url: "http://www.google.co.in"
    11. anchors.fill: parent
    12.  
    13. }
    14.  
    15. toolBar: ReaderToolBar {
    16. id: tb
    17. width: 1400
    18. height: 50
    19. //anchors.top: parent
    20. // color: "transparent"
    21. MouseArea {
    22. anchors.fill: parent
    23. onClicked: console.log("clicked tool bar")
    24. }
    25. }
    26. function showPage(content,baseUrl)
    27. {
    28. currentwebview.loadHtml(content,baseUrl)
    29. }
    30.  
    31. Image {
    32. id: prevPage
    33. width: 50
    34. height: 50
    35. anchors.top: parent.top
    36. anchors.left: parent.left
    37. anchors.leftMargin: 20
    38. anchors.topMargin: (parent.height / 2 ) - 40
    39. source: "images/prev_button.png"
    40. visible: true
    41. MouseArea {
    42. anchors.fill: parent
    43. onClicked:{ console.log("Clicked previous page")}
    44. }
    45. }
    46.  
    47. Image {
    48. id: nextPage
    49. width: 50
    50. height: 50
    51. anchors.top: parent.top
    52. anchors.right: parent.right
    53. anchors.rightMargin: 1
    54. anchors.topMargin: (parent.height / 2 ) - 40
    55. source: "images/next_button.png"
    56. visible: true
    57. MouseArea {
    58. anchors.fill: parent
    59. onClicked: console.log("clicked nextpage")
    60. }
    61. }
    62. }
    To copy to clipboard, switch view to plain text mode 

  8. #28
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to set QWebEngineView on QQuickView

    How is ReaderToolBar defined?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #29
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to set QWebEngineView on QQuickView

    Quote Originally Posted by ejoshva View Post
    if it's one or two pages, then its fine I guess. But I will have whole book say 500 pages to show. If I am showing only one page at a time then not a problem. I have reflow layout means , I will just keep scrolling and pages will be shown.
    One other option might be to just load a basic HTML document with an embedded display section (frame, whatever) and get the content through a web sockets connection with the host application (or using QtWebChannel).

    Cheers,
    _

  10. #30
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to set QWebEngineView on QQuickView

    Quote Originally Posted by wysota View Post
    How is ReaderToolBar defined?
    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. Rectangle{
    4. id: tbrect
    5. width: 1200
    6. height: 50
    7. // color: "transparent"
    8. visible: true
    9.  
    10. MouseArea {
    11. anchors.fill: parent
    12. hoverEnabled: true
    13. }
    14. function showicons()
    15. {
    16. libicon.visible = true
    17. }
    18. Image {
    19. id: libicon
    20. x: 30
    21. smooth: true
    22. height: 36
    23. width: 36
    24. anchors.bottom: parent.bottom
    25. anchors.bottomMargin: 8
    26. source: "qrc:/images/library.png"
    27. visible: true
    28.  
    29. MouseArea {
    30. id: libiconma
    31. anchors.fill: parent
    32. onClicked: {
    33.  
    34. //rw.showlibrary()
    35. console.log("library")
    36. }
    37. }
    38. }
    39. Component.onCompleted: showicons()
    40. }
    To copy to clipboard, switch view to plain text mode 

  11. #31
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to set QWebEngineView on QQuickView

    You have covered your toolbar with another mouse area so events are not reaching the ones inside the tool bar.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #32
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to set QWebEngineView on QQuickView

    click event in the prevpage/nextpage is also not caught

    Actually the ones inside the tool bar is not detected so I wrote a mousearea in the main.qml, where it's used.


    Added after 52 minutes:


    When I have the QML as Application window, I am able to set the page to display for webengineview using setHtml().
    But when it's Rectangle, I am not able to set the page using SetHtml().

    I have used QQuickWidget and using setSource()
    Qt Code:
    1. ReaderView.cpp ( inherits QQuickWidget)
    2. ReaderView::ReaderView()
    3. {
    4. setSource(QUrl("qrc:/Main.qml"));
    5. QQmlEngine engine;
    6. QQmlComponent component(&engine);
    7. component.loadUrl(QUrl("qrc:/Main.qml"));
    8. QObject *object = component.create();
    9. Decrypt *decrypt = new Decrypt();
    10. QString content = decrypt->decryptFile("/Users/user/learnOnContent/LifeSciences_Grade1020151518_1963/Pages/pag001.html", 'A');
    11. QUrl baseUrl = QUrl("file:///Users/user/ssparklBookStore/LifeSciences_Grade1020151518_1963/Pages/pag001.html");
    12. QMetaObject::invokeMethod(object, "showPage", Q_ARG(QVariant, content),Q_ARG(QVariant, baseUrl));
    13. }
    14.  
    15. Main.qml
    16. Rectangle {
    17. id : readview
    18. width: 1200
    19. height: 800
    20. visible: true
    21. WebEngineView {
    22. id: currentWebView
    23. url: "http://www.google.co.in"
    24. anchors.fill: parent
    25. }
    26. function showPage(content,baseUrl)
    27. {
    28. currentWebView.loadHtml(content,baseUrl)
    29. }
    30.  
    31. ReaderToolBar {
    32. id: tb
    33. width: 1400
    34. height: 50
    35. //anchors.top: parent
    36. color: "transparent"
    37. }
    38. }
    To copy to clipboard, switch view to plain text mode 

    showPage(content,baseUrl) is getting called but webEngineView is displaying only google.com and not the page set by setHtml()
    Last edited by ejoshva; 12th May 2015 at 11:17.

  13. #33
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to set QWebEngineView on QQuickView

    I would recommend to expose the HTML as a property on a context object instead.

    Then you can do something like
    Qt Code:
    1. WebEngineView {
    2. readonly property string htmlContent: contextObject.htmlProperty
    3. onHtmlContentChanged: loadHtml(htmlContent, contextObject.baseUrl);
    4. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  14. #34
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to set QWebEngineView on QQuickView

    Qt Code:
    1. WebEngineView {
    2. id: currentWebView
    3. url: "http://www.google.co.in"
    4. anchors.fill: parent
    5. readonly property string htmlContent: readView.getHtmlContent()
    6. onHtmlContentChanged: loadHtml(htmlContent, readView.getBaseUrl());
    7. }
    8.  
    9.  
    10.  
    11. ReaderView::ReaderView()
    12. {
    13. setSource(QUrl("qrc:/Main.qml"));
    14. QQmlEngine engine;
    15. QQmlContext *context = new QQmlContext(engine.rootContext());
    16. context->setContextProperty("readView",this);
    17. QQmlComponent component(&engine);
    18. component.loadUrl(QUrl("qrc:/Main.qml"));
    19. QObject *object = component.create(context);
    20. }
    To copy to clipboard, switch view to plain text mode 

    Getting error as
    qrc:/Main.qml:18: ReferenceError: readView is not defined
    qrc:/Main.qml:18: TypeError: Property 'getHtmlContent' of object QQuickWidget(0x7f9d5a49f7b0) is not a function
    Last edited by ejoshva; 13th May 2015 at 06:12.

  15. #35
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to set QWebEngineView on QQuickView

    What is the base class of ReaderView?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #36
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to set QWebEngineView on QQuickView

    Quote Originally Posted by ejoshva View Post
    Qt Code:
    1. WebEngineView {
    2. id: currentWebView
    3. url: "http://www.google.co.in"
    4. anchors.fill: parent
    5. readonly property string htmlContent: readView.getHtmlContent()
    6. onHtmlContentChanged: loadHtml(htmlContent, readView.getBaseUrl());
    7. }
    To copy to clipboard, switch view to plain text mode 
    My recommendation is to use a property, not a function.
    Otherwise this is a one time thing, the onHtmlContentChanged will only be invoked on the very first assignment.
    You want to be able to push new HTML, which would be automatic with properties.

    QML automatically reevaluates expressions that contain properties when any of these properties change, so called property bindings.

    It also seems strange that you would want to destroy the QQmlEngine right after creating and using it. Don't you want to keep your QML parts running during the applicatino life time?

    Cheers,
    _

  17. #37
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to set QWebEngineView on QQuickView

    Quote Originally Posted by wysota View Post
    What is the base class of ReaderView?
    QQuickWidgets


    Added after 15 minutes:


    @anda_skoa
    you mean to set a property in qml like
    Qt Code:
    1. property string htmldata : rdView.getHtmlContent()
    2. WebEngineView {
    3. id: currentWebView
    4. url: "http://www.google.co.in"
    5. anchors.fill: parent
    6. readonly property string htmlContent: htmldata
    7. onHtmlContentChanged: loadHtml(htmlContent, readView.getBaseUrl());
    8. }
    To copy to clipboard, switch view to plain text mode 

    or I will have to set the property in cpp and then use it over hear. In that case, how to set the property ?

    Kindly pardon for my ignorance
    Last edited by ejoshva; 13th May 2015 at 08:04.

  18. #38
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to set QWebEngineView on QQuickView

    Quote Originally Posted by ejoshva View Post
    QQuickWidgets
    So why are you instantiating a new QML engine and loading the same QML document twice?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #39
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to set QWebEngineView on QQuickView

    I didn't realize that. Thanks for pointing out that.
    Now have modified it.

    Qt Code:
    1. ReaderView::ReaderView()
    2. {
    3.  
    4. QQmlContext *context = new QQmlContext(this->rootContext());
    5. context->setContextProperty("rdView",this);
    6. context->setContextProperty("content",content);
    7. setSource(QUrl("qrc:/Main.qml"));
    8. }
    9.  
    10. WebEngineView {
    11. id: currentWebView
    12. url: "http://www.google.co.in"
    13. anchors.fill: parent
    14. readonly property string htmlContent: content
    15. onHtmlContentChanged: loadHtml(htmlContent, rdView.getBaseUrl());
    16. }
    To copy to clipboard, switch view to plain text mode 

    But I am getting error as
    qrc:/Main.qml:18: ReferenceError: content is not defined
    qrc:/Main.qml:19: TypeError: Property 'getBaseUrl' of object QQuickWidget(0x7fe328f0eb40) is not a function
    qrc:/Main.qml:18: ReferenceError: content is not defined

    Not sure, what I am missing


    Added after 7 minutes:


    Got it working by setting as property.

    Qt Code:
    1. WebEngineView {
    2. id: currentWebView
    3. url: "http://www.google.co.in"
    4. anchors.fill: parent
    5. readonly property string htmlContent: content
    6. onHtmlContentChanged: loadHtml(htmlContent, baseUrl);
    7. }
    8.  
    9. ReaderView::ReaderView()
    10. {
    11. Decrypt *decrypt = new Decrypt();
    12. QString content = decrypt->decryptFile("/Users/user/learnOnContent/LifeSciences_Grade1020151518_1963/Pages/pag001.html", 'A');
    13. setHtmlContent(content);
    14. QUrl baseUrl = QUrl("file:///Users/user/ssparklBookStore/LifeSciences_Grade1020151518_1963/Pages/pag001.html");
    15. setBaseUrl(baseUrl);
    16.  
    17. QQmlContext *context = this->rootContext();
    18. context->setContextProperty("rdView",this);
    19. QVariant qv(content);
    20. context->setContextProperty("content",qv);
    21. context->setContextProperty("baseUrl",baseUrl);
    22. setSource(QUrl("qrc:/Main.qml"));
    23. }
    To copy to clipboard, switch view to plain text mode 

    Thanks anda_skoa
    Last edited by ejoshva; 13th May 2015 at 14:01.

  20. #40
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to set QWebEngineView on QQuickView

    Quote Originally Posted by ejoshva View Post
    or I will have to set the property in cpp and then use it over hear. In that case, how to set the property ?
    Have a Q_PROPERTY on the object you are exporting.

    This is the easiest way of having changable content exported from C++ .
    Whenever your C++ code needs QML to update its bindings, it just emits the property's change notification signal.
    See comment #33 on how that looks from QML.

    Qt Code:
    1. class ReaderView : // whatever your base class is
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY(QString content READ content NOTIFY contentChanged)
    5. public:
    6.  
    7. QString content() const: // that is the part after READ above
    8.  
    9. signals:
    10. void contentChanged();
    11. };
    To copy to clipboard, switch view to plain text mode 
    So whenever you emit contentChanged(), the property "content" (that's the part before READ) will be reevaluated, by QQmlEngine calling the property's READ function content().

    Cheers,
    _

Similar Threads

  1. Loading QDeclarativeView in QWebEngineView
    By ejoshva in forum Newbie
    Replies: 8
    Last Post: 7th May 2015, 09:38
  2. Replies: 8
    Last Post: 23rd April 2015, 12:17
  3. QQuickView or QQmlApplicationEngine or QQuickWidget
    By ustulation in forum Qt Quick
    Replies: 0
    Last Post: 18th January 2015, 13:16
  4. Repaint a QML Scene (QQuickView)
    By alizadeh91 in forum Qt Programming
    Replies: 0
    Last Post: 23rd July 2013, 09:54
  5. Set fixed window size with QQuickView
    By cristeab in forum Qt Quick
    Replies: 1
    Last Post: 31st January 2013, 10:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.