全部博文(156)
分类:
2010-10-04 19:57:18
先看下效果图:
http://blog.chinaunix.net/photo/116111_101004193852.jpg
在url处输入 即可进入百度首页
代码实现:
browser::browser(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::browser)
{
ui->setupUi(this);
//webView是一个QWebview类定义的对象
QObject::connect(ui->webView, SIGNAL(titleChanged(QString)),
this, SLOT(UpdateTitle()));
QObject::connect(ui->webView, SIGNAL(urlChanged(QUrl)), this,
SLOT(UpdateUrl()));
//添加一个进度条
progressBar = new QProgressBar;
ui->statusBar->addWidget(progressBar);
QObject::connect(ui->webView, SIGNAL(loadProgress(int)), this,
SLOT(UpdateProgressBar(int)));
QObject::connect(ui->SourceLookaction, SIGNAL(triggered()), this,
SLOT(GetSource()));
}
browser::~browser()
{
delete ui;
}
void browser::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void browser::on_UrllineEdit_returnPressed()
{
ui->webView->load(QUrl(ui->UrllineEdit->text()));
}
void browser::UpdateTitle()
{
this->setWindowTitle(ui->webView->title() + "--farSight");
}
void browser::UpdateUrl()
{
ui->UrllineEdit->setText(ui->webView->url().toString());
}
void browser::on_GoToButton_clicked()
{
ui->webView->load(QUrl(ui->UrllineEdit->text()));
}
//前进
void browser::on_ForwardButton_clicked()
{
ui->webView->forward();;
}
//后退
void browser::on_BackwardButton_clicked()
{
ui->webView->back();
}
void browser::UpdateProgressBar(int i)
{
qDebug()<<"i = " < this->progressBar->setValue(i);
}
//获取源码
void browser::GetSource()
{
QString source(ui->webView->page()->currentFrame()->toHtml());
childWindow *d = new childWindow;
d->setSource(source);
d->show();
}