mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
Доделал сообщения в Мессенджере
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
|
||||
MsgWidget::MsgWidget(QString avatar, AligneAvatar aligneAvatar, int width, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::MsgWidget)
|
||||
ui(new Ui::MsgWidget),
|
||||
widthEdit(100)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@@ -59,7 +60,7 @@ void MsgWidget::setAvatar(QString avatar)
|
||||
void MsgWidget::setWidth(int width)
|
||||
{
|
||||
this->setFixedWidth(width);
|
||||
ui->textEdit->setFixedWidth(width - 200);
|
||||
widthEdit = width - 200;
|
||||
}
|
||||
|
||||
void MsgWidget::setText(QString text)
|
||||
@@ -71,11 +72,19 @@ 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; // отступы
|
||||
|
||||
this->setFixedHeight(textRect.height()+X + 20);
|
||||
|
||||
ui->textEdit->setFixedWidth(textRect.width()+X);
|
||||
ui->textEdit->setFixedHeight(textRect.height()+X);
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->textEdit->setFixedWidth(textRect.width()+X);
|
||||
ui->textEdit->setFixedHeight(textRect.height()+X);
|
||||
this->setFixedHeight(textRect.height()+X + 20);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ private slots:
|
||||
|
||||
private:
|
||||
Ui::MsgWidget *ui;
|
||||
|
||||
int widthEdit;
|
||||
};
|
||||
|
||||
#endif // MSGWIDGET_H
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||
<enum>QAbstractScrollArea::AdjustIgnored</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user