derrickbj
13th October 2006, 19:33
Does anybody know if there's anything special that needs to be done for QTextBrowser::forward(), backward(), and home() to work? How/where does it store the history? I'm trying to implement a simple HTML browser with only forward, backward, and home buttons. I'm able to load the application fine and open the "index.html" file. i'm able to click on links and have them load fine, but when I trigger the forward and backward actions, the TextBrowser->forward() and TextBrowser->backward() slots don't seem to work. So I didn't know if there was anything "history-wise" I needed to do. Based on the documentation, it seems pretty straightforward, which is why I'm stumped!
HelpWindow::HelpWindow(QWidget *parent, Qt::WFlags fl)
: QMainWindow(parent, fl)
{
setupUi( this );
setupActions();
setupToolbar();
openFile("index.html");
QDir appDir;
QString helpDir = appDir.currentPath() + "/doc/";
QString helpImages = helpDir + "images";
QStringList helpPaths;
helpPaths<<helpDir<<helpImages;
helpBrowser->setSearchPaths(helpPaths);
}
HelpWindow::~HelpWindow()
{
}
void HelpWindow::setupActions()
{
forwardAct = new QAction(QIcon(":MyApp/images/forward_arrow.png"), tr("Forward"), this);
forwardAct->setStatusTip(tr("Go Forward"));
connect(forwardAct, SIGNAL(triggered()), this, SLOT(goForward()));
backAct = new QAction(QIcon(":MyApp/images/back_arrow.png"), tr("Back"), this);
backAct->setStatusTip(tr("Go Back"));
connect(backAct, SIGNAL(triggered()), this, SLOT(goBack()));
homeAct = new QAction(QIcon(":MyApp/images/home.png"), tr("Home"), this);
homeAct->setStatusTip(tr("Go Home"));
connect(homeAct, SIGNAL(triggered()), this, SLOT(helpBrowser->home()));
}
void HelpWindow::setupToolbar()
{
navToolBar = addToolBar(tr("Nav"));
navToolBar->addAction(backAct);
navToolBar->addAction(forwardAct);
navToolBar->addAction(homeAct);
}
void HelpWindow::openFile(const QString &fileName)
{
QDir appDir;
QString fileToLoad = appDir.currentPath() + "/doc/"+fileName;
QFileInfo fileInfo(fileToLoad);
if (fileInfo.exists()) loadFile(fileToLoad);
}
void HelpWindow::loadFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, "Program Help", QString("Cannot read file %1: \n%2. ")
.arg(fileName).arg(file.errorString()));
return;
}
QTextStream in(&file);
helpBrowser->setHtml(in.readAll());
}
void HelpWindow::goForward()
{
helpBrowser->forward();
}
void HelpWindow::goBack()
{
helpBrowser->backward();
}
HelpWindow::HelpWindow(QWidget *parent, Qt::WFlags fl)
: QMainWindow(parent, fl)
{
setupUi( this );
setupActions();
setupToolbar();
openFile("index.html");
QDir appDir;
QString helpDir = appDir.currentPath() + "/doc/";
QString helpImages = helpDir + "images";
QStringList helpPaths;
helpPaths<<helpDir<<helpImages;
helpBrowser->setSearchPaths(helpPaths);
}
HelpWindow::~HelpWindow()
{
}
void HelpWindow::setupActions()
{
forwardAct = new QAction(QIcon(":MyApp/images/forward_arrow.png"), tr("Forward"), this);
forwardAct->setStatusTip(tr("Go Forward"));
connect(forwardAct, SIGNAL(triggered()), this, SLOT(goForward()));
backAct = new QAction(QIcon(":MyApp/images/back_arrow.png"), tr("Back"), this);
backAct->setStatusTip(tr("Go Back"));
connect(backAct, SIGNAL(triggered()), this, SLOT(goBack()));
homeAct = new QAction(QIcon(":MyApp/images/home.png"), tr("Home"), this);
homeAct->setStatusTip(tr("Go Home"));
connect(homeAct, SIGNAL(triggered()), this, SLOT(helpBrowser->home()));
}
void HelpWindow::setupToolbar()
{
navToolBar = addToolBar(tr("Nav"));
navToolBar->addAction(backAct);
navToolBar->addAction(forwardAct);
navToolBar->addAction(homeAct);
}
void HelpWindow::openFile(const QString &fileName)
{
QDir appDir;
QString fileToLoad = appDir.currentPath() + "/doc/"+fileName;
QFileInfo fileInfo(fileToLoad);
if (fileInfo.exists()) loadFile(fileToLoad);
}
void HelpWindow::loadFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, "Program Help", QString("Cannot read file %1: \n%2. ")
.arg(fileName).arg(file.errorString()));
return;
}
QTextStream in(&file);
helpBrowser->setHtml(in.readAll());
}
void HelpWindow::goForward()
{
helpBrowser->forward();
}
void HelpWindow::goBack()
{
helpBrowser->backward();
}