Доделал Мессенджер

This commit is contained in:
krivoshein
2024-12-24 12:23:22 +03:00
parent 30ad6330a4
commit bf7b0ac741
45 changed files with 784 additions and 464 deletions

View File

@@ -1,6 +1,5 @@
#include "msgwidget.h"
#include "ui_msgwidget.h"
#include <QSizePolicy>
MsgWidget::MsgWidget(QString avatar, AligneAvatar aligneAvatar, int width, QWidget *parent) :
QWidget(parent),
@@ -72,19 +71,22 @@ void MsgWidget::on_textEdit_textChanged()
{
QString text = ui->textEdit->toPlainText();
QFontMetrics metricsFont(ui->textEdit->font()); //метрики шрифта
QRect textRect = metricsFont.boundingRect(QRect(0, 0, 0, 0), 0, text); //геометрические параметры текста (высота/ширина в пикселях)
//геометрические параметры текста (высота/ширина в пикселях). В одну строку
QRect textRect = metricsFont.boundingRect(QRect(0, 0, 0, 0), 0, text);
int X = 10; // отступы
if(textRect.width() > widthEdit)
{
{//Не помещается в одну строку
textRect = metricsFont.boundingRect(QRect(0, 0, widthEdit, 10), Qt::TextWordWrap, text);
ui->textEdit->setFixedHeight(textRect.height()+X);
this->setFixedHeight(textRect.height()+X + 20);
ui->textEdit->setFixedHeight(textRect.height() + X);
this->setFixedHeight(textRect.height() + X + 20);
}
else
{
ui->textEdit->setFixedWidth(textRect.width()+X);
ui->textEdit->setFixedHeight(textRect.height()+X);
this->setFixedHeight(textRect.height()+X + 20);
{//В одну строку
ui->textEdit->setFixedWidth(textRect.width() + X);
ui->textEdit->setFixedHeight(textRect.height() + X);
this->setFixedHeight(textRect.height() + X + 20);
}
}