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?