PDA

View Full Version : Set button invisiable on a plugin, will cause page scroll to top?



hcfalan
24th September 2015, 13:58
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.
11390
The layout of TTFilePlugin should be like this:

void TTFilePluginUi::setupUi()
{
QRect rectIconLabel(0,0,48,48);
mIconLabel = new QLabel(owner);
mIconLabel->setGeometry(rectIconLabel);

QRect rectNameLabel(rectIconLabel.right() + 10, rectIconLabel.top(), 100, 24);
mFileNameLabel = new QLabel(owner);
mFileNameLabel->setAlignment(Qt::AlignLeft|Qt::AlignTop);
mFileNameLabel->setGeometry(rectNameLabel);

QRect rectSizeLabel(rectNameLabel.right() + 10, rectNameLabel.top(), 60, 24);
mFileSizeLabel = new QLabel(owner);
mFileSizeLabel->setAlignment(Qt::AlignRight|Qt::AlignTop);
mFileSizeLabel->setGeometry(rectSizeLabel);

QRect rectProgressBar(rectNameLabel.left(), rectNameLabel.bottom() + 4,
rectNameLabel.width() + 10 + rectSizeLabel.width(), 20);
mProgressBar = new QProgressBar(owner);
mProgressBar->setTextVisible(false);
mProgressBar->setGeometry(rectProgressBar);

QRect rectRecvButton(rectIconLabel.left(), rectIconLabel.bottom() + 5, 60, 30);
mRecvButton = new QPushButton("Receive", owner);
mRecvButton->setGeometry(rectRecvButton);

QRect rectOpenButton(rectRecvButton.right() + 10, rectIconLabel.bottom() + 5, 60, 30);
mOpenButton = new QPushButton("Open", owner);
mOpenButton->setGeometry(rectOpenButton);

QRect rectSaveAsButton(rectOpenButton.right()+10, rectIconLabel.bottom() + 5, 60, 30);
mSaveAsButton = new QPushButton("Save As", owner);
mSaveAsButton->setGeometry(rectSaveAsButton);
}

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:

void onReceiveButtonClicked() {
ui->mReceiveButton->setEnabled(false);
}

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

d_stranz
24th September 2015, 16:19
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.

hcfalan
25th September 2015, 02:17
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?

d_stranz
25th September 2015, 22:14
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.