Results 1 to 4 of 4

Thread: Set button invisiable on a plugin, will cause page scroll to top?

  1. #1
    Join Date
    Jun 2015
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Set button invisiable on a plugin, will cause page scroll to top?

    I have build a chat application, based on QT widgets. For display message in list, I choosed QWebView, because the message data will text, image, audio, file transfer. For display file transfer message, I use 'object' tag in html, and custom a plugin named 'TTFilePlugin' which extends from QWidget.
    message-display.jpg
    The layout of TTFilePlugin should be like this:
    Qt Code:
    1. void TTFilePluginUi::setupUi()
    2. {
    3. QRect rectIconLabel(0,0,48,48);
    4. mIconLabel = new QLabel(owner);
    5. mIconLabel->setGeometry(rectIconLabel);
    6.  
    7. QRect rectNameLabel(rectIconLabel.right() + 10, rectIconLabel.top(), 100, 24);
    8. mFileNameLabel = new QLabel(owner);
    9. mFileNameLabel->setAlignment(Qt::AlignLeft|Qt::AlignTop);
    10. mFileNameLabel->setGeometry(rectNameLabel);
    11.  
    12. QRect rectSizeLabel(rectNameLabel.right() + 10, rectNameLabel.top(), 60, 24);
    13. mFileSizeLabel = new QLabel(owner);
    14. mFileSizeLabel->setAlignment(Qt::AlignRight|Qt::AlignTop);
    15. mFileSizeLabel->setGeometry(rectSizeLabel);
    16.  
    17. QRect rectProgressBar(rectNameLabel.left(), rectNameLabel.bottom() + 4,
    18. rectNameLabel.width() + 10 + rectSizeLabel.width(), 20);
    19. mProgressBar = new QProgressBar(owner);
    20. mProgressBar->setTextVisible(false);
    21. mProgressBar->setGeometry(rectProgressBar);
    22.  
    23. QRect rectRecvButton(rectIconLabel.left(), rectIconLabel.bottom() + 5, 60, 30);
    24. mRecvButton = new QPushButton("Receive", owner);
    25. mRecvButton->setGeometry(rectRecvButton);
    26.  
    27. QRect rectOpenButton(rectRecvButton.right() + 10, rectIconLabel.bottom() + 5, 60, 30);
    28. mOpenButton = new QPushButton("Open", owner);
    29. mOpenButton->setGeometry(rectOpenButton);
    30.  
    31. QRect rectSaveAsButton(rectOpenButton.right()+10, rectIconLabel.bottom() + 5, 60, 30);
    32. mSaveAsButton = new QPushButton("Save As", owner);
    33. mSaveAsButton->setGeometry(rectSaveAsButton);
    34. }
    To copy to clipboard, switch view to plain text mode 

    After page loaded, I scroll to page end to make file transfer message appear. when i click the 'Receive' button on TTFilePlugin, the page auto scroll to Top!

    The slot code of 'Receive' button clicked signal fired like this:
    Qt Code:
    1. void onReceiveButtonClicked() {
    2. ui->mReceiveButton->setEnabled(false);
    3. }
    To copy to clipboard, switch view to plain text mode 

    If I comment the line 'ui->mReceiveButton->setEnabled(false);' and try again, the page will NOT auto scroll to top. Why?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,319
    Thanks
    316
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Set button invisiable on a plugin, will cause page scroll to top?

    Probably it is because you have changed the content of the QWebView, and it must repaint to show the updated content. Since it has no memory of the previous content, it resets the scrollbar to the top of the page.

  3. The following user says thank you to d_stranz for this useful post:

    hcfalan (25th September 2015)

  4. #3
    Join Date
    Jun 2015
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Set button invisiable on a plugin, will cause page scroll to top?

    Thank you, d_stranz. Yes, after button on plugin pressed, I found that the QWebPage's repaintRequested signal fired. It's the reason why page scroll to top. But the QWebPage's contentsChanged signal NOT fired. I am confused that what cause the page repaint?

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,319
    Thanks
    316
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Set button invisiable on a plugin, will cause page scroll to top?

    From the docs:

    QWebPage::contentsChanged()
    This signal is emitted whenever the text in form elements changes as well as other editable content.
    QWebPage::repaintRequested()
    This signal is emitted whenever this QWebPage should be updated.
    You don't have any form fields on the page that are being edited. contentsChanged() is not emitted when the page needs to be redrawn, but when the user edits something.

Similar Threads

  1. Scroll to the text on the page
    By ejoshva in forum Newbie
    Replies: 0
    Last Post: 21st May 2015, 07:09
  2. how to scroll Qgraphic_view by a push button
    By shivendra46d in forum Newbie
    Replies: 1
    Last Post: 6th April 2013, 08:42
  3. Replies: 0
    Last Post: 8th November 2011, 11:16
  4. Scroll Buttons in page Area for QTAbwidget
    By vaibhav in forum Qt Programming
    Replies: 3
    Last Post: 26th August 2011, 14:59
  5. Replies: 1
    Last Post: 15th August 2011, 09:08

Tags for this Thread

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.