add scroll bar to properties in cardinfotextwidget (#6201)

* add scroll bar to properties in cardinfotextwidget

* remove resizeevent trigger
This commit is contained in:
ebbit1q
2025-10-03 04:55:18 +02:00
committed by GitHub
parent c5b361e94d
commit a69bfb8cb8
2 changed files with 39 additions and 15 deletions

View File

@@ -6,32 +6,55 @@
#include <QGridLayout>
#include <QLabel>
#include <QScrollArea>
#include <QScrollBar>
#include <QSizePolicy>
#include <QTextEdit>
CardInfoTextWidget::CardInfoTextWidget(QWidget *parent) : QFrame(parent), info(nullptr)
{
nameLabel = new QLabel;
nameLabel->setOpenExternalLinks(false);
nameLabel->setWordWrap(true);
connect(nameLabel, SIGNAL(linkActivated(const QString &)), this, SIGNAL(linkActivated(const QString &)));
propsLabel = new QLabel;
propsLabel->setOpenExternalLinks(false);
propsLabel->setWordWrap(true);
connect(propsLabel, SIGNAL(linkActivated(const QString &)), this, SIGNAL(linkActivated(const QString &)));
textLabel = new QTextEdit();
textLabel->setReadOnly(true);
textLabel->setMinimumSize(35, 35);
propsScroll = new QScrollArea(this);
propsScroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
propsScroll->setWidgetResizable(true);
propsScroll->setAlignment(Qt::AlignLeft | Qt::AlignTop);
propsScroll->setContentsMargins(0, 0, 0, 0);
propsScroll->setFrameStyle(QFrame::NoFrame);
propsScroll->setWidget(propsLabel);
// blend into normal background color, note that themes may override this!
propsScroll->viewport()->setStyleSheet("QWidget{background: transparent}");
auto *grid = new QGridLayout(this);
grid->addWidget(nameLabel, 0, 0);
grid->addWidget(textLabel, 1, 0, -1, 2);
grid->addWidget(propsScroll, 0, 0);
grid->addWidget(textLabel, 1, 0);
grid->setRowStretch(0, 2);
grid->setRowStretch(1, 1);
grid->setColumnStretch(1, 1);
retranslateUi();
}
void CardInfoTextWidget::setTexts(const QString &propsText, const QString &textText)
{
propsScroll->setMaximumHeight(0); // reset the max height, otherwise the scrollbar will blink in and out sometimes
propsLabel->setText(propsText);
propsScroll->setMinimumWidth(propsLabel->minimumWidth() + propsScroll->verticalScrollBar()->width());
propsScroll->setMaximumHeight(propsLabel->sizeHint().height());
textLabel->setText(textText);
}
void CardInfoTextWidget::setCard(CardInfoPtr card)
{
if (card == nullptr) {
nameLabel->setText("");
textLabel->setText("");
setTexts("", "");
return;
}
@@ -61,14 +84,12 @@ void CardInfoTextWidget::setCard(CardInfoPtr card)
}
text += "</table>";
nameLabel->setText(text);
textLabel->setText(card->getText());
setTexts(text, card->getText());
}
void CardInfoTextWidget::setInvalidCardName(const QString &cardName)
{
nameLabel->setText(tr("Unknown card:") + " " + cardName);
textLabel->setText("");
setTexts(tr("Unknown card:") + " " + cardName, "");
}
void CardInfoTextWidget::retranslateUi()
@@ -77,5 +98,5 @@ void CardInfoTextWidget::retranslateUi()
* There's no way we can really translate the text currently being rendered.
* The best we can do is invalidate the current text.
*/
setInvalidCardName("");
setTexts("", "");
}

View File

@@ -11,6 +11,7 @@
#include <QFrame>
class QLabel;
class QScrollArea;
class QTextEdit;
class CardInfoTextWidget : public QFrame
@@ -18,9 +19,11 @@ class CardInfoTextWidget : public QFrame
Q_OBJECT
private:
QLabel *nameLabel;
QLabel *propsLabel;
QScrollArea *propsScroll;
QTextEdit *textLabel;
CardInfoPtr info;
void setTexts(const QString &propsText, const QString &textText);
public:
explicit CardInfoTextWidget(QWidget *parent = nullptr);