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?
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?