Guidance for Qt/QML chat attachment rows and message bubbles: Flow wrapping, image/file chip alignment, right/left alignment, and width/height sizing quirks...
Fix and tune QML chat attachment layouts so chips/images wrap in rows, align to the correct side, preserve ordering, and keep message bubbles from stretching full width.
Flow.width to its own implicitWidth.layoutDirection, anchors, and model order.Layout.preferredWidth and Flow width to a max ratio or fixed pixel cap.Flow an explicit width based on available space (e.g., chatArea.width - margins).Math.max(0, ...) to avoid negative widths during resize.implicitHeight over height when itβs driven by a Flow.Example:
Item {
implicitHeight: attachmentsFlow.implicitHeight
Flow {
id: attachmentsFlow
width: Math.max(0, Math.min(chatArea.width - 120, chatArea.width * 0.65))
spacing: 8
}
}
anchors.right: parent.right on the Flow container.layoutDirection: Qt.RightToLeft for a right-aligned wrap.RightToLeft.RightToLeft.Order rules:
RightToLeft shows newest on the right.LeftToRight.Layout.preferredWidth so bubbles donβt stretch full width, even for long text or many attachments.0.6β0.7) or a fixed max pixel value.Example:
Rectangle {
Layout.preferredWidth: Math.min(msgText.implicitWidth + 24, chatArea.width * 0.65)
Layout.preferredHeight: msgText.height + 16
}
qApp->thread()), otherwise QClipboard may return empty.QClipboard::image() but add fallbacks: application/x-qt-image, then mime->imageData() to QImage or QPixmap.Example:
if (QThread::currentThread() != qApp->thread())
return "";
QImage image = clipboard->image();
if (image.isNull() && mime->hasFormat("application/x-qt-image")) {
QByteArray raw = mime->data("application/x-qt-image");
QDataStream stream(&raw, QIODevice::ReadOnly);
stream >> image;
if (stream.status() != QDataStream::Ok)
image = QImage();
}
if (image.isNull()) {
QVariant data = mime->imageData();
if (data.canConvert<QImage>())
image = data.value<QImage>();
else if (data.canConvert<QPixmap>())
image = data.value<QPixmap>().toImage();
}
if (image.isNull())
return "";
if (image.format() != QImage::Format_RGBA8888)
image = image.convertToFormat(QImage::Format_RGBA8888);
image.setColorSpace(QColorSpace::SRgb);
image = image.copy();
Flow.width: implicitWidth often collapses to a single-column layout.height instead of implicitHeight on containers causes clipping or over-expansion.layoutDirection keeps the wrap left-biased.Text.elide and a fixed max width.