QTableWidgetItem *host = new QTableWidgetItem(localHostName);
QTableWidgetItem *ip = new QTableWidgetItem(ipAddress);
ui->tableWidget->insertRow(0);
ui->tableWidget->setItem(0,0,user);
ui->tableWidget->setItem(0,1,host);
ui->tableWidget->setItem(0,2,ip);
ui->textBrowser->setTextColor(Qt::gray);
ui->textBrowser->setCurrentFont(QFont("Times New Roman",10));
ui->textBrowser->append(tr("%1 在线!").arg(userName));
//ui->onlineUser->setText(tr("在线人数:%1").arg(ui->tableWidget->rowCount()));
sendMessage(NewParticipant);
}
}
//处理用户离开
void Widget::participantLeft(QString userName,QString localHostName,QString time)
{
int rowNum = ui->tableWidget->findItems(localHostName,Qt::MatchExactly).first()->row();
ui->tableWidget->removeRow(rowNum);
ui->textBrowser->setTextColor(Qt::gray);
ui->textBrowser->setCurrentFont(QFont("Times New Roman",10));
ui->textBrowser->append(tr("%1 于 %2 离开!").arg(userName).arg(time));
//ui->onlineUser->setText(tr("在线人数:%1").arg(ui->tableWidget->rowCount()));
}
Widget::~Widget()
{
delete ui;
}
void Widget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
QString Widget::getIP() //获取 ip 地址
{