Page 3 of 6 FirstFirst 12345 ... LastLast
Results 41 to 60 of 113

Thread: How to set QWebEngineView on QQuickView

  1. #41
    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. ReaderView.h
    2. class ReaderView : public QQuickWidget
    3. {
    4. Q_OBJECT
    5. Q_PROPERTY(QString content READ content NOTIFY contentChanged)
    6. public:
    7. ReaderView();
    8. ~ReaderView();
    9. QString content() const;
    10. void setContent(const QString &value) {
    11. if (value != htmlContent) {
    12. htmlContent = value;
    13. emit contentChanged();
    14. }
    15. }
    16. signals:
    17. void contentChanged();
    18. public slots:
    19. QUrl getBaseUrl() const;
    20. void setBaseUrl(const QUrl &value);
    21.  
    22. private :
    23. QString htmlContent;
    24. QUrl baseUrl;
    25. };
    26.  
    27. ReaderView.cpp
    28. ReaderView::ReaderView()
    29. {
    30. Decrypt *decrypt = new Decrypt();
    31. QString content = decrypt->decryptFile("/Users/user/learnOnContent/LifeSciences_Grade1020151518_1963/Pages/pag001.html", 'A');
    32. setHtmlContent(content);
    33. QUrl baseUrl = QUrl("file:///Users/user/ssparklBookStore/LifeSciences_Grade1020151518_1963/Pages/pag001.html");
    34. setBaseUrl(baseUrl);
    35.  
    36. QQmlContext *context = this->rootContext();
    37. context->setContextProperty("rdView",this);
    38. setSource(QUrl("qrc:/Main.qml"));
    39. }
    40.  
    41. Main.qml
    42. WebEngineView {
    43. id: currentWebView
    44. // url: "http://www.google.co.in"
    45. anchors.fill: parent
    46. readonly property string htmlContent: rdView.content
    47. onHtmlContentChanged: loadHtml(htmlContent, rdView.getBaseUrl());
    48. }
    To copy to clipboard, switch view to plain text mode 

    Now getting error as
    UUndefined symbols for architecture x86_64:
    "vtable for ReaderView", referenced from:
    ReaderView::ReaderView() in ReaderView.o
    ReaderView::~ReaderView() in ReaderView.o
    NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)


    Added after 10 minutes:


    Got the issue resolved.

    Issue was with .pro file.

    Missed adding QT += gui
    Last edited by ejoshva; 14th May 2015 at 07:02.

  2. #42
    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
    Got the issue resolved.

    Issue was with .pro file.

    Missed adding QT += gui
    Are you sure it wasn't that you didn't define body for constructor and destructor?
    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. #43
    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 am sure, missing "gui" in pro file was the issue. Constructor and destructor body I have added. Even in the code sample pasted here is constructor.

  4. #44
    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

    The vtable error usually means that you did not re-run qmake after adding Q_OBJECT to a class that had already been part of the project.

    Btw, why not make the baseUrl a property as well?

    Cheers,
    _

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

    Default Re: How to set QWebEngineView on QQuickView

    Yes, I have to make base url property as well.

    Thanks anda_skoa and wysota for your values inputs.

    I have implemented mouseMoveEvent in WebEngineView class.

    But after reading from the internet QTBUG-43602 and from one of your posts got to know that QWebEngineView doesn't capture mouseEvents and it's a limitation.

    Also suggestion was given as to monitor QObject::childEvent of the QWebEngineView and install an event filter when a new child QWidget appear during page loads

    how do I do this?

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

    Default Re: How to set QWebEngineView on QQuickView

    I tried implement eventfilter by installing it. But mouse events are not captured in the event()->type.

    How to capture the mouseevent in qwebengineview

  7. #47
    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 did you install the event filter on?
    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.


  8. #48
    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. ReaderMain::ReaderMain(QWidget *parent)
    2. : QQuickWidget(parent)
    3. {
    4. webView = new WebEngineView(this);
    5. tool = new toolbar(this);
    6. this->installEventFilter(webView);
    7. }
    8.  
    9. bool WebEngineView::eventFilter(QObject *obj, QEvent *event)
    10. {
    11. qDebug()<<obj->metaObject()->className() <<" : "<<event->type();
    12.  
    13. if(event->type() == QEvent::MouseButtonPress)
    14. {
    15. qDebug()<<"mouse press";
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 
    The mouse events are of value 2,3,4,5. But I dont receive these events only window focus, window enable, window disable events (12,25,25) events are received.

    What I want to actually do is on click drag and release (meaning some text), I want to display a menu where option will be shown as to highlight or annotation.

  9. #49
    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

    Are you sure you know what you are doing? How is your webView object related to WebEngineView declaration you have (or at least had yesterday) in your QML document?
    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.


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

    Default Re: How to set QWebEngineView on QQuickView

    Yesterday I was trying out with QML for WebEngineView.

    Now the code is different, I will be using that QML WebEngineView at later point of time.

    Currently I am doing as bellow

    Qt Code:
    1. WebEngineView::WebEngineView(QWidget *parent)
    2. : QWebEngineView(parent)
    3. {
    4. setEnabled(true);
    5. setGeometry(0,0,dw.width(),dw.height());
    6. decrypt = new Decrypt();
    7. setPageContent(decrypt->decryptFile("/Users/user/learnOnContent/LifeSciences_Grade1020151518_1963/Pages/pag002.html", 'A'));
    8. setUrl(QUrl("file:///Users/user/ssparklBookStore/LifeSciences_Grade1020151518_1963/Pages/pag002.html"));
    9. loadCurrentPage();
    10. prev = new QPushButton(this);
    11. prev->setGeometry(30,(dw.height()/2)-50,50,50);
    12. prev->setStyleSheet("border:1px");
    13. prev->setIcon(QIcon(QString::fromUtf8(":/images/prev_button.png")));
    14. prev->setIconSize(QSize(50, 50));
    15.  
    16. next = new QPushButton(this);
    17. next->setGeometry(dw.width()-90,(dw.height()/2)-50,50,50);
    18. next->setStyleSheet("border:1px");
    19. next->setIcon(QIcon(QString::fromUtf8(":/images/next_button.png")));
    20. next->setIconSize(QSize(50, 50));
    21. connect(prev,SIGNAL(clicked()),this,SLOT(loadPreviousPage()));
    22. connect(next,SIGNAL(clicked()),this,SLOT(loadNextPage()));
    23.  
    24. }
    25.  
    26.  
    27. toolbar::toolbar(QWidget *parent) : QQuickWidget(parent)
    28. {
    29. QQmlContext *objectContext = this->rootContext();
    30. objectContext->setContextProperty("tb", this);
    31. setSource(QUrl("qrc:/ReaderToolBar.qml"));
    32. setResizeMode(QQuickWidget::SizeRootObjectToView);
    33. }
    34.  
    35.  
    36. ReaderMain::ReaderMain(QWidget *parent)
    37. : QQuickWidget(parent)
    38. {
    39. webView = new WebEngineView(this);
    40. tool = new toolbar(this);
    41.  
    42. // this->installEventFilter(webView);
    43.  
    44. this->hideToolBarWid(true);
    45. tool->setStyleSheet("background-color: transparent;");
    46. connect(tool, SIGNAL(s_showlib()), this, SLOT(showlibrary()));
    47. connect(tool,SIGNAL(s_showTOCFromTB()), this, SLOT(showtocinwebview()));
    48. connect(tool,SIGNAL(s_fixLayout()),this,SLOT(loadfxlayout()));
    49. connect(tool, SIGNAL(s_showreflow()), this, SLOT(loadflowpage()));
    50. connect(tool, SIGNAL(s_hideToolBar(bool)), this, SLOT(hideToolBarWid(bool)));
    51. }
    To copy to clipboard, switch view to plain text mode 

    currently I am using this way.

    Here I would want to capture the mouse events on the WebEngineView

  11. #51
    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

    Installing an event filter on the webview doesn't make sense. The bug report you mentioned said you had to do it on a child of the view.
    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. #52
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to set QWebEngineView on QQuickView

    Yes Wysota. But I am not sure how to implement that.

  13. #53
    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

    I believe it is described in the report.
    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.


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

    Default Re: How to set QWebEngineView on QQuickView

    childEvent link gives details regarding QWebEngineView::childEvent.
    But I am not getting how to implement this.
    Please provide some sample code, how to implement this childEvent().

  15. #55
    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
    childEvent link gives details regarding QWebEngineView::childEvent.
    But I am not getting how to implement this.
    Please provide some sample code, how to implement this childEvent().
    Do you understand what you need to do? Or is the next question you ask going to be "what do I put there?" and the next one "please provide me with a sample code of an event filter"?
    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. #56
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to set QWebEngineView on QQuickView

    I have written the code for event filter, What I am not clear is how to implement as child of the WebEngineView.
    I have said this in few post earlier as well.

    Now I have written the eventFilter() in the class which as inherited QWebEngineView, so that makes it the child class. But I don't get the events for mouse.
    So what is this child class supposed to be?

  17. #57
    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
    I have written the code for event filter, What I am not clear is how to implement as child of the WebEngineView.
    What do you not understand? Did you read the docs on what childEvent() does? Did you go through the docs of QChildEvent? What options does it present?

    Now I have written the eventFilter() in the class which as inherited QWebEngineView, so that makes it the child class. But I don't get the events for mouse.
    Which clearly indicates you have no idea what the problem is and what you are supposed to do with it.

    Child of object A is an object B for whom A is set as its QObject::parent(). childEvent lets you be notified when a child object (B) is added or removed from a particular object (A) which lets you install an event filter (on B).
    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.


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

    Default Re: How to set QWebEngineView on QQuickView

    Below is the code in which I have implemented the childEvent.
    I am able to catch the mouse events
    Qt Code:
    1. #include "WebEngineView.h"
    2.  
    3. WebEngineView::WebEngineView(QWidget *parent)
    4. : QWebEngineView(parent)
    5. {
    6. installEventFilter(this);
    7. setEnabled(true);
    8. setGeometry(0,0,dw.width(),dw.height());
    9. load(QUrl("http://www.thehindu.com"));
    10. }
    11.  
    12. WebEngineView::~WebEngineView()
    13. {
    14.  
    15. }
    16.  
    17. bool WebEngineView::eventFilter(QObject *obj, QEvent *event)
    18. {
    19.  
    20. switch(event->type())
    21. {
    22. case QEvent::ChildAdded:
    23. {
    24. QChildEvent* ce = static_cast<QChildEvent*>(event);
    25. // Install the filter to each new child object created
    26. ce->child()->installEventFilter(this);
    27. break;
    28. }
    29. case QEvent::ChildRemoved:
    30. {
    31. QChildEvent* ce = static_cast<QChildEvent*>(event);
    32. // Remove the the filter from each new child object removed
    33. ce->child()->removeEventFilter(this);
    34. break;
    35. }
    36. case QEvent::MouseButtonPress:
    37. {
    38. QMouseEvent* me = static_cast<QMouseEvent*>(event);
    39. if (me->button() == Qt::LeftButton)
    40. {
    41. event->accept();
    42. }
    43. if (me->button() == Qt::RightButton)
    44. {
    45. event->accept();
    46. }
    47. break;
    48. }
    49. case QEvent::MouseButtonRelease:
    50. {
    51. QMouseEvent* me = static_cast<QMouseEvent*>(event);
    52. qDebug()<<"selected Text : "<<this->selectedText();
    53. break;
    54. }
    55. case QEvent::MouseMove:
    56. {
    57. QMouseEvent* me = static_cast<QMouseEvent*>(event);
    58. break;
    59. }
    60. case QEvent::MouseButtonDblClick:
    61. {
    62. QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
    63. if (mouseEvent && mouseEvent->button() == Qt::LeftButton)
    64. {
    65. qDebug()<<"clicked position : " << mouseEvent->pos();
    66. }
    67. else if (event->type() == QEvent::Wheel)
    68. {
    69. QWheelEvent *wheelEvent = static_cast<QWheelEvent*>(event);
    70. if (wheelEvent->buttons() == Qt::RightButton)
    71. {
    72. event->ignore();
    73. return false;
    74. }
    75. if (wheelEvent->modifiers().testFlag(Qt::ControlModifier))
    76. {
    77. event->accept();
    78. break;
    79. }
    80. }
    81. }
    82. default:
    83.  
    84. }
    85. return QWidget::eventFilter(obj, event);
    86. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ejoshva; 15th June 2015 at 12:03.

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

    Default Re: How to set QWebEngineView on QQuickView

    How to get the selected text from page loaded in the WebEngineView which is loaded as QML element.
    (i.e.) just as we get page()->selectedText() from the QWebEngineView.

    Qt Code:
    1. //ReaderView.qml
    2. import QtQuick 2.4
    3. import QtQuick.Controls 1.3
    4. import QtWebEngine 1.0
    5.  
    6. Rectangle {
    7. id: rect1
    8. height: 600
    9. color: "white"
    10.  
    11.  
    12. WebEngineView {
    13. id: currentWebview
    14. objectName: "webView"
    15. url: "http://www.google.co.in"
    16. anchors.fill: parent
    17. readonly property string htmlContent: content
    18. onHtmlContentChanged: loadHtml(htmlContent, baseUrl);
    19. MouseArea {
    20. anchors.fill: parent
    21. onClicked: {
    22. console.log("clicked")
    23. }
    24. onPressed: {
    25. console.log("x="+mouseX)
    26. console.log("y="+mouseY)
    27. }
    28. onReleased: {
    29. console.log("release x: "+mouseX)
    30. console.log("release y: "+mouseY)
    31. }
    32.  
    33. }
    34. }
    35. }
    36.  
    37. //ReadWidget.cpp
    38. readwidget::readwidget(QWidget *parent) : QQuickWidget(parent)
    39. {
    40. engine = QQuickWidget::engine();
    41. root = this->rootContext();
    42.  
    43. /* Setting the current object into context of QML source */
    44. root->setContextProperty("rw", this);
    45.  
    46. /*Initializing the variables for the usage in QML*/
    47. Decrypt *decrypt = new Decrypt();
    48. QString content = decrypt->decryptFile("/Users/user/ssparklContent/LifeSciences_Grade1020151518_1963/Pages/10_chap05.html", 'A');
    49.  
    50. QUrl baseUrl = QUrl("file:///Users/user/ssparklContent/LifeSciences_Grade1020151518_1963/Pages/10_chap05.html");
    51. QVariant pgContent(content);
    52.  
    53. root->setContextProperty("content",pgContent);
    54. root->setContextProperty("baseUrl",baseUrl);
    55.  
    56.  
    57. /* Setting the QML source as ReaderView.qml to be executed from
    58.   * current object */
    59. setSource(QUrl("qrc:/ReaderView.qml"));
    60. QQmlComponent component(engine);
    61. component.loadUrl(QUrl("qrc:/ReaderView.qml"));
    62. object = component.create(root);
    63.  
    64. setResizeMode(QQuickWidget::SizeRootObjectToView);
    65.  
    66. }
    To copy to clipboard, switch view to plain text mode 

  20. #60
    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

    Maybe there is a way to do that through running JavaScript in the Web context?
    I.e. calling runJavaScript() with some script code that uses "browser" methods of getting the selected text?

    Something like

    Qt Code:
    1. runJavaScript("window.getSelection()", function(result) { console.log("selected Text=" + result);} );
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

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