Results 1 to 15 of 15

Thread: Problems with setScrollBarPolicy in QwebView

  1. #1
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Problems with setScrollBarPolicy in QwebView

    Hi All,

    There’s an application running on an embedded device which uses QWebView(actually, a class derived from QWebView to be more precise). Now, in the constructor of that class the scrollbarpolicy is being set to “As needed”

    Qt Code:
    1. page()->currentframe()->setScrollBarPolicy(Qt::Horizontal,ScrollBarAsNeeded);
    2. page()->currentframe()->setScrollBarPolicy(Qt::Vertical,ScrollBarAsNeeded);
    To copy to clipboard, switch view to plain text mode 

    So now when we try to load a page, the scrollbars show up(or dont show up) depending on the size of the web page. All fine up to here.
    Now, we have an OSK (OnScreenKeyboard) kind of thing that comes up whenever a user activates an input control. This OSK covers the half screen.
    Now as per the design requirement, we are required to hide the scrollbars when the OSK is up and showing.
    For this I put some checks at places where the OSK gets to show up, to set the scrollbar policy to AlwaysOff. And when I am done with the OSK and close it …at that place I am again setting the policy to AsNeeded.
    The problem here is that when the OSK gets closed, the scroll bars still do not appear, even when the page is too big to fit in the viewport.

    The slightest mention of the scrollbar is done only at 3 places:
    1. Constructor
    2. When OSK is activated
    3. When OSK is closed

    I am not able to understand what code I am missing which results in scrollbar not getting displayed, once it has been hidden and then tried to get displayed again.

    Could anyone please be so kind to help me on this.

    Not sure whether I am right, but I kind of doubt, is getting the current frame from the page, the right widget to set the scrollBarPolicy. Sorry for the lengthy post, but I am working for the first time on Qt and QWebkit.

  2. #2
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Problems with setScrollBarPolicy in QwebView

    Have you tried what happens when you set the policy to Qt::ScrollBarAlwaysOn instead of Qt::ScrollBarAsNeeded after your OSK is closed?

    Does it show up?

  3. #3
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setScrollBarPolicy in QwebView

    Thanks for your reply.

    Yes, I did try that. But the problem is that doing so displays the Scrollbar even if the web page is small enough to fit in the view-port.

    Meanwhile, I am writing a dummy application to simulate that defect.

  4. #4
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Problems with setScrollBarPolicy in QwebView

    Try then a hack and see if that helps:
    page()->currentframe()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOn);
    page()->currentframe()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAsNeeded);

    and same for vertical

  5. #5
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setScrollBarPolicy in QwebView

    Rachol, I tried that, but no luck. It seems that my code is ignoring the scroll bar policy, completely after the OSK is closed. I mean, I called an explicit
    Qt Code:
    1. this->update();
    To copy to clipboard, switch view to plain text mode 

    but that too is not serving any purpose.

  6. #6
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Problems with setScrollBarPolicy in QwebView

    I keep guessing:

    QSize size = page()->viewportSize();
    size.rheight() -= 1;
    page()->setViewportSize(size);

    Does this show the scrollbar?

  7. #7
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setScrollBarPolicy in QwebView

    Rochel, I am out of my workplace now. Sure, will try that first thing in the morning when I turn up at my office. Thanks

  8. #8
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setScrollBarPolicy in QwebView

    Okay, today I wrote a dummy application to demonstrate my problem. It consists of Main(source file), MainWindow(source and header files). Here it is:

    Main.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include "MainWindow.h"
    3.  
    4. int main(int argc, char * argv[])
    5. {
    6. QApplication app(argc, argv);
    7. MainWindow browser;
    8. browser.show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    MainWindow.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include <QtWebKit>
    3. #include "MainWindow.h"
    4.  
    5. MainWindow::MainWindow()
    6. {
    7. m_bFullMode = true;
    8.  
    9. //allocate memory to member widgets
    10. view = new QWebView(this);
    11. addrBar = new QLineEdit(this);
    12. pushButton = new QPushButton("Resize");
    13.  
    14. //create a toolbar
    15. QToolBar *toolBar = addToolBar(tr("Navigation"));
    16. toolBar->addAction(view->pageAction(QWebPage::Back));
    17. toolBar->addAction(view->pageAction(QWebPage::Forward));
    18. toolBar->addAction(view->pageAction(QWebPage::Reload));
    19. toolBar->addAction(view->pageAction(QWebPage::Stop));
    20. toolBar->addWidget(addrBar);
    21. toolBar->addWidget(pushButton);
    22.  
    23. //make connections between Signals and Slots
    24. connect(addrBar, SIGNAL(returnPressed()), SLOT(goToAddress()));
    25. connect(pushButton,SIGNAL(clicked()),SLOT(toggleSize()));
    26.  
    27. setCentralWidget(view);
    28. this->resize(450,400);
    29.  
    30. view->resize(450,250);
    31.  
    32. view->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAsNeeded);
    33. view->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAsNeeded);
    34.  
    35. view->load(QUrl("http://www.google.com"));
    36. }
    37.  
    38.  
    39. void MainWindow::goToAddress()
    40. {
    41. QUrl url = QUrl(addrBar->text());
    42. view->load(url);
    43. view->setFocus();
    44. }
    45.  
    46. void MainWindow::toggleSize()
    47. {
    48.  
    49. if(m_bFullMode == true)
    50. {
    51. m_bFullMode = false;
    52. view->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff); //Line A
    53. view->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); //Line B
    54. view->resize(450,200);
    55. }
    56. else
    57. {
    58. m_bFullMode = true;
    59. view->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOn); //Line C
    60. view->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOn); //Line D
    61.  
    62. QSize size = view->page()->viewportSize();
    63. size.rheight() -= 1;
    64. view->page()->setViewportSize(size);
    65. view->resize(450,300);
    66. }
    67. }
    To copy to clipboard, switch view to plain text mode 

    MainWindow.h

    Qt Code:
    1. #include <QtGui>
    2.  
    3. #ifndef MAINWINDOW_H
    4. #define MAINWINDOW_H
    5.  
    6. class QWebView;
    7. class QLineEdit;
    8.  
    9. class MainWindow : public QMainWindow
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. MainWindow();
    15.  
    16. protected slots:
    17.  
    18. void toggleSize();
    19. void goToAddress();
    20.  
    21. private:
    22.  
    23. QWebView *view;
    24. QLineEdit *addrBar;
    25. QPushButton *pushButton;
    26. bool m_bFullMode;
    27. };
    28.  
    29. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    This application, too suffers from the same problem, if "Resize" button is hit to toggle the view.

  9. #9
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setScrollBarPolicy in QwebView

    Can somebody guide me as to what am I doing wrong in the code?

  10. #10
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Problems with setScrollBarPolicy in QwebView

    Try this:

    Qt Code:
    1. void MainWindow::toggleSize()
    2. {
    3.  
    4. if(m_bFullMode == true)
    5. {
    6. m_bFullMode = false;
    7. view->resize(450,300);
    8. view->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff); //Line A
    9. view->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOff); //Line B
    10. view->page()->view()->update();
    11. }
    12. else
    13. {
    14. m_bFullMode = true;
    15. view->resize(450,300);
    16. view->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOn); //Line C
    17. view->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical,Qt::ScrollBarAlwaysOn); //Line D
    18. view->page()->view()->update();
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setScrollBarPolicy in QwebView

    Rochel, still not working.

  12. #12
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Problems with setScrollBarPolicy in QwebView

    Are you sure? I am running it right now and it seems to work... What problem do you see now?

    Edit: But it doesn't when I set ScrollBarAsNeeded....
    Last edited by Rachol; 20th June 2011 at 11:47.

  13. The following user says thank you to Rachol for this useful post:

    shariqkhan (20th June 2011)

  14. #13
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setScrollBarPolicy in QwebView

    Oh, actually right now I tried it on my project application. It does not seem to work over there neither with ScrollBarAsNeeded nor with ScrollBarAlwaysOn. Though, eventually I have to get it working with "AsNeeded".

    However, when I get home, I will try it on the dummy application, in that case. And if it works there, may be I can get a way to fix things in the real application as well.
    Many thanks.

  15. #14
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Problems with setScrollBarPolicy in QwebView

    I think this must be considered as QtWebKit bug...

  16. #15
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setScrollBarPolicy in QwebView

    Exactly my thoughts indeed. But since I am a novice, I need to confirm this before I take to the bugs forum. I do not want to be balsed beacuse of some silly mistake on my part.

Similar Threads

  1. Replies: 8
    Last Post: 3rd September 2013, 09:51
  2. Replies: 2
    Last Post: 23rd July 2010, 14:53
  3. QWebView - Problems with line spacing
    By ckovacs in forum Qt Programming
    Replies: 0
    Last Post: 7th October 2009, 23:05
  4. Problems of embedded QWebView in QGraphicsView
    By naruto_9w in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2009, 15:22
  5. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 15:39

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.