12 #include <QtWebEngineWidgets> 18 m_ptxt =
new QLineEdit(
"http://www.bhv.ru");
19 m_pwv =
new QWebEngineView;
20 m_pcmdBack =
new QPushButton(
"<");
21 m_pcmdForward =
new QPushButton(
">");
23 m_pcmdBack->setEnabled(
false);
24 m_pcmdForward->setEnabled(
false);
26 QProgressBar* pprb =
new QProgressBar;
27 QPushButton* pcmdGo =
new QPushButton(
"&Go");
28 QPushButton* pcmdStop =
new QPushButton(
"&Stop");
29 QPushButton* pcmdRefresh =
new QPushButton(
"&Refresh");
31 connect(pcmdGo, SIGNAL(clicked()), SLOT(slotGo()));
32 connect(m_ptxt, SIGNAL(returnPressed()), SLOT(slotGo()));
33 connect(m_pcmdBack, SIGNAL(clicked()), m_pwv, SLOT(back()));
34 connect(m_pcmdForward, SIGNAL(clicked()), m_pwv, SLOT(forward()));
35 connect(pcmdRefresh, SIGNAL(clicked()), m_pwv, SLOT(reload()));
36 connect(pcmdStop, SIGNAL(clicked()), m_pwv, SLOT(stop()));
37 connect(m_pwv, SIGNAL(loadProgress(
int)), pprb, SLOT(setValue(
int)));
38 connect(m_pwv, SIGNAL(loadFinished(
bool)), SLOT(slotFinished(
bool)));
41 QHBoxLayout* phbx =
new QHBoxLayout;
42 phbx->addWidget(m_pcmdBack);
43 phbx->addWidget(m_pcmdForward);
44 phbx->addWidget(pcmdStop);
45 phbx->addWidget(pcmdRefresh);
46 phbx->addWidget(m_ptxt);
47 phbx->addWidget(pcmdGo);
49 QVBoxLayout* playout =
new QVBoxLayout;
50 playout->addLayout(phbx);
51 playout->addWidget(m_pwv);
52 playout->addWidget(pprb);
59 void WebBrowser::slotGo()
61 if (!m_ptxt->text().startsWith(
"ftp://")
62 && !m_ptxt->text().startsWith(
"http://")
63 && !m_ptxt->text().startsWith(
"gopher://")
65 m_ptxt->setText(
"http://" + m_ptxt->text());
67 m_pwv->load(QUrl(m_ptxt->text()));
71 void WebBrowser::slotFinished(
bool bOk)
74 m_pwv->setHtml(
"<CENTER>An error has occured" 75 " while loading the web page</CENTER>" 79 m_ptxt->setText(m_pwv->url().toString());
81 m_pcmdBack->setEnabled(m_pwv->page()->history()->canGoBack());
82 m_pcmdForward->setEnabled(m_pwv->page()->history()->canGoForward());
WebBrowser(QWidget *wgt=0)