Results 1 to 5 of 5

Thread: QTextBrowser::forward() and backward()

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2006
    Posts
    38
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    5
    Thanked 3 Times in 2 Posts

    Default Re: QTextBrowser::forward() and backward()

    Hey, Thanks for the response.

    I did try connecting the forward() and backward() slots directly, as you see with the homeAct action and the home() slot, but this didn't work either. So I broke them out in order to use qDebug() to make sure the trigger() action was happening, which it is.

    Here's my header

    Qt Code:
    1. #ifndef HELPWINDOW_H
    2. #define HELPWINDOW_H
    3.  
    4. #include "ui_HelpWindow.h"
    5.  
    6. class QToolBar;
    7.  
    8. class HelpWindow : public QMainWindow, private Ui::HelpWindow
    9. {
    10. Q_OBJECT
    11. public:
    12. HelpWindow(QWidget* parent = 0, Qt::WFlags fl = 1);
    13. ~HelpWindow();
    14.  
    15. private slots:
    16. void goForward();
    17. void goBack();
    18.  
    19.  
    20. private:
    21. void openFile(const QString &fileName);
    22. void loadFile(const QString &fileName);
    23. void setupActions();
    24. void setupToolbar();
    25.  
    26. QToolBar *navToolBar;
    27. QAction* backAct;
    28. QAction* forwardAct;
    29. QAction* homeAct;
    30.  
    31. };
    32. #endif //helpwindow_h
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTextBrowser::forward() and backward()

    This works:

    Qt Code:
    1. #include <QApplication>
    2. #include <QTextBrowser>
    3. #include <QWidget>
    4. #include <QVBoxLayout>
    5. #include <QPushButton>
    6. #include <QUrl>
    7.  
    8. int main(int argc, char **argv){
    9. QApplication app(argc, argv);
    10. QVBoxLayout *layout = new QVBoxLayout();
    11. QPushButton *frwd = new QPushButton("Forward");
    12. QPushButton *bck = new QPushButton("Back");
    13. layout->addWidget(frwd);
    14. layout->addWidget(bck);
    15. layout->addWidget(&brws);
    16. w.setLayout(layout);
    17. QObject::connect(frwd, SIGNAL(clicked()), &brws, SLOT(forward()));
    18. QObject::connect(bck, SIGNAL(clicked()), &brws, SLOT(backward()));
    19. QObject::connect(&brws, SIGNAL(forwardAvailable(bool)), frwd, SLOT(setEnabled(bool)));
    20. QObject::connect(&brws, SIGNAL(backwardAvailable(bool)), bck, SLOT(setEnabled(bool)));
    21. brws.setSource(QUrl::fromLocalFile("file1.html"));
    22. w.show();
    23. return app.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

    The magic seems to be in using setSource() instead of setHtml().

  3. The following 2 users say thank you to wysota for this useful post:

    derrickbj (13th October 2006), jml (13th December 2007)

  4. #3
    Join Date
    Sep 2006
    Posts
    38
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    5
    Thanked 3 Times in 2 Posts

    Default Re: QTextBrowser::forward() and backward()

    Yep! it was in the setSource()...thanks!

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
  •  
Qt is a trademark of The Qt Company.