mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-14 00:51:48 +08:00
add button functionality
This commit is contained in:
@ -26,9 +26,11 @@ UserInfoWidget::UserInfoWidget(const UserInfo& userInfo, QWidget *parent)
|
||||
avatarBtn->setFixedSize(75, 75);
|
||||
avatarBtn->setIconSize(QSize(75, 75));
|
||||
avatarBtn->setIcon(userInfo.avatar);
|
||||
avatarBtn->setStyleSheet("QPushButton { border: none; background-color: transparent; }");
|
||||
|
||||
QString labelStyle = "QLabel { font-weight: 800; padding-left: 20px;}";
|
||||
QString btnStyle = "QPushButton { border: 1px solid rgb(100, 100, 100); border-radius: 5px; background-color: rgb(240, 240, 240); color: rgb(0, 0, 0); }";
|
||||
QString btnStyle = "QPushButton { border: 1px solid rgb(100, 100, 100); border-radius: 5px; background-color: rgb(240, 240, 240); color: rgb(0, 0, 0);}";
|
||||
//QString btnStyle = "";
|
||||
btnStyle += "QPushButton:pressed { background-color: rgb(205, 205, 205); }";
|
||||
|
||||
int width = 80;
|
||||
@ -107,16 +109,39 @@ UserInfoWidget::UserInfoWidget(const UserInfo& userInfo, QWidget *parent)
|
||||
|
||||
// 9. 初始化按钮的禁用关系
|
||||
// 判定依据就是拿着当前用户的 userId, 在 DataCenter 的好友列表中, 查询即可.
|
||||
//DataCenter* dataCenter = DataCenter::getInstance();
|
||||
//auto* myFriend = dataCenter->findFriendById(this->userInfo.userId);
|
||||
//if (myFriend == nullptr) {
|
||||
// // 不是好友
|
||||
// sendMessageBtn->setEnabled(false);
|
||||
// deleteFriendBtn->setEnabled(false);
|
||||
//}
|
||||
//else {
|
||||
// // 是好友
|
||||
// applyBtn->setEnabled(false);
|
||||
//}
|
||||
DataCenter* dataCenter = DataCenter::getInstance();
|
||||
auto* myFriend = dataCenter->findFriendById(this->userInfo.userId);
|
||||
if (myFriend == nullptr) {
|
||||
// 不是好友
|
||||
sendMessageBtn->setEnabled(false);
|
||||
deleteFriendBtn->setEnabled(false);
|
||||
|
||||
}
|
||||
/*sendMessageBtn->setObjectName("sendMessageBtn");
|
||||
deleteFriendBtn->setObjectName("deleteFriendBtn");*/
|
||||
|
||||
sendMessageBtn->setStyleSheet("QPushButton { border: 1px solid rgb(200, 200, 200); border-radius: 5px; background-color: rgb(240, 240, 240); color: rgb(150, 150, 150); }");
|
||||
deleteFriendBtn->setStyleSheet("QPushButton { border: 1px solid rgb(200, 200, 200); border-radius: 5px; background-color: rgb(240, 240, 240); color: rgb(150, 150, 150); }");
|
||||
|
||||
}
|
||||
else {
|
||||
// 是好友
|
||||
applyBtn->setEnabled(false);
|
||||
applyBtn->setStyleSheet("QPushButton { border: 1px solid rgb(200, 200, 200); border-radius: 5px; background-color: rgb(240, 240, 240); color: rgb(150, 150, 150); }");
|
||||
|
||||
}
|
||||
|
||||
//初始化信号槽
|
||||
initSingleSlot();
|
||||
}
|
||||
|
||||
void UserInfoWidget::initSingleSlot()
|
||||
{
|
||||
connect(sendMessageBtn, &QPushButton::clicked, this, [=]() {
|
||||
//拿到主窗口的指针,通过主窗口,前面实现的切换到会话这样的功能,直接调用即可
|
||||
MainWidget* mainWidget = MainWidget::getInstance();
|
||||
mainWidget->switchSession(userInfo.userId);
|
||||
|
||||
//把当前模态窗口关闭
|
||||
this->close();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user