Results 1 to 4 of 4

Thread: Issue with loading the link clicked page in new tab.

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

    Default Issue with loading the link clicked page in new tab.

    I am making a browser in mac 10.9.5 where in whenever a link is clicked, I want to open that link in a new tab.

    Attached the code which I tried to implement the same, but I am getting link page in a new window.

    Kindly help me to resolve this issue.



    LinkInNewTab.zip

    Qt Code:
    1. #include "WebEnginePage.h"
    2.  
    3. WebEnginePage::WebEnginePage(QObject *parent)
    4. : QWebEnginePage(parent)
    5. {
    6. connect(this,SIGNAL(urlChanged(QUrl)),this,SLOT(loadInTab(QUrl)));
    7. }
    8.  
    9. WebEnginePage::~WebEnginePage()
    10. {
    11.  
    12. }
    13.  
    14. void WebEnginePage::loadInTab(QUrl url)
    15. {
    16. qDebug()<<"Page : "<<url;
    17. emit pageInNewTab(url);
    18.  
    19. }
    20.  
    21.  
    22. #include "WebEngineView.h"
    23.  
    24. WebEngineView::WebEngineView(QWidget *parent)
    25. : QWebEngineView(parent)
    26. {
    27. webPage = new WebEnginePage(this);
    28. setPage(webPage);
    29. setGeometry(0,35,dw.width(),dw.height()-35);
    30.  
    31. // connect(page(),SIGNAL(urlChanged(QUrl)),this,SLOT(loadInNewTab(QUrl)));
    32. connect(page(),SIGNAL(pageInNewTab(QUrl)),this,SLOT(loadInNewTab(QUrl)));
    33. hide();
    34. connect(this, SIGNAL(loadFinished(bool)), this, SLOT(onPageLoadFinished(bool)));
    35. }
    36.  
    37. void WebEngineView::onPageLoadFinished(bool value)
    38. {
    39. qDebug()<<"WebEngineView::onPageLoadFinished";
    40. show();
    41. emit newTab(this);
    42. }
    43. WebEngineView::~WebEngineView()
    44. {
    45.  
    46. }
    47.  
    48. WebEngineView *WebEngineView::createWindow(QWebEnginePage::WebWindowType type)
    49. {
    50. Q_UNUSED(type);
    51. qDebug()<<"WebEngineView::createWindow";
    52. WebEngineView *webView = new WebEngineView();
    53. qDebug()<<"Index : "<<++index;
    54. WebEnginePage *newWeb = new WebEnginePage(webView);
    55. webView->setAttribute(Qt::WA_DeleteOnClose, true);
    56. webView->setPage(newWeb);
    57. //webView->show();
    58.  
    59. return webView;
    60. }
    61.  
    62.  
    63.  
    64. void WebEngineView::loadInNewTab(QUrl url)
    65. {
    66. qDebug()<<"WebEngineView "<<index<<" : "<<url;
    67. // createWindow(QWebEnginePage::WebBrowserTab);
    68. }
    69. int WebEngineView::getIndex() const
    70. {
    71. return index;
    72. }
    73.  
    74. void WebEngineView::setIndex(int value)
    75. {
    76. index = value;
    77. }
    78.  
    79.  
    80. #include "TabWindow.h"
    81.  
    82. TabWindow::TabWindow(QWidget *parent)
    83. : QMainWindow(parent)
    84. {
    85. weView = new WebEngineView(this);
    86. weView->setGeometry(0,50,dw.width(),dw.height());
    87. loadedUrl = QUrl("http://www.google.co.in");
    88. //weView->load(QUrl(loadedUrl));
    89. weView->webPage->load(loadedUrl);
    90. QWidget *centralWidget = new QWidget(this);
    91. tabWidget = new QTabWidget(centralWidget);
    92. tabWidget->setTabsClosable(true);
    93. //tabWidget->setElideMode(Qt::ElideRight);
    94.  
    95. tabWidget->setFixedSize(dw.width(),dw.height());
    96. loadedUrl = QUrl("http://www.google.co.in");
    97. tabWidget->addTab(weView,loadedUrl.host());
    98. setCentralWidget(centralWidget);
    99. currentIndex = 0;
    100. weView->setIndex(currentIndex);
    101.  
    102. //weViewNew = new WebEngineView(this);
    103. connect(weView,SIGNAL(newTab(WebEngineView&)),this,SLOT(loadNewTab(WebEngineView7)));
    104. connect(tabWidget,SIGNAL(tabCloseRequested(int)),this,SLOT(closeTab(int)));
    105. }
    106.  
    107. TabWindow::~TabWindow()
    108. {
    109.  
    110. }
    111.  
    112. void TabWindow::closeTab(int index)
    113. {
    114. tabWidget->removeTab(index);
    115. }
    116.  
    117.  
    118. void TabWindow::loadNewTab(WebEngineView *webView)
    119. {
    120. //webView->show();
    121. tabWidget->addTab(webView,webView->webPage->url().host());
    122. //tabWidget->setCurrentIndex(currentIndex);
    123. qDebug()<<"TabWindow::loadNewTab : ";
    124.  
    125.  
    126. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ejoshva; 9th June 2015 at 11:57.

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

    Default Re: Issue with loading the link clicked page in new tab.

    I just checked the WebWindowType being triggered from QWebPage. It's 1 which is WebBrowserWindow.

    I want to make it WebBrowserTab.

    Kindly help me to open the link in a new tab instead of new window.

  3. #3
    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: Issue with loading the link clicked page in new tab.

    WebView does not have "tabs". For a browser that is a separate window and what you do with that window (e.g. make it a tab) is your own responsibility.
    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.


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

    Default Re: Issue with loading the link clicked page in new tab.

    Thanks Wysota for the info.

    TabBrowser.zip Attachment is the working code.

    I have resolved it. Now I am able to open the link in a new tab.

Similar Threads

  1. Replies: 0
    Last Post: 10th April 2015, 08:54
  2. QWebView page loading fails after file downloading
    By mentalmushroom in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2011, 15:57
  3. Replies: 1
    Last Post: 13th October 2010, 17:45
  4. Need your help... loading image on my widgetstack page..
    By megabeat in forum Qt Programming
    Replies: 4
    Last Post: 30th January 2007, 15:00
  5. How to open external page link using tabwidget
    By jyoti in forum Qt Programming
    Replies: 2
    Last Post: 13th November 2006, 11:43

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.