94 lines
3.2 KiB
C++
94 lines
3.2 KiB
C++
|
#include <QDebug>
|
||
|
#include <QApplication>
|
||
|
#include <QFontMetrics>
|
||
|
#include <QTextOption>
|
||
|
#include <QWidget>
|
||
|
#include <QHBoxLayout>
|
||
|
|
||
|
void testFont() {
|
||
|
QFont font("Arial", 21);
|
||
|
//font.setItalic(m_attr.fontItalics);
|
||
|
font.setStyleStrategy(QFont::NoAntialias);
|
||
|
QFontMetricsF metric(font);
|
||
|
QFontMetrics metricI(font);
|
||
|
qDebug()<<"QFontMetrics";
|
||
|
qDebug()<<" leading"<<metric.leading();
|
||
|
qDebug()<<" ascent"<<metric.ascent();
|
||
|
qDebug()<<" descent"<<metric.descent();
|
||
|
qDebug()<<" ttl"<<metric.leading()+metric.ascent()+metric.descent();
|
||
|
qDebug()<<" height"<<metric.height();
|
||
|
qDebug()<<" lineSpacing"<<metric.lineSpacing()<<metricI.lineSpacing();
|
||
|
qDebug()<<" capHeight"<<metric.capHeight();
|
||
|
qDebug()<<" horizontalAdvance"<<metric.horizontalAdvance("0")<<metricI.horizontalAdvance("0");
|
||
|
qDebug()<<" boundingRect"<<metric.boundingRect("0").width()<<metricI.boundingRect("0").width();
|
||
|
qDebug()<<" Bearing"<<metric.leftBearing('0')<<metric.rightBearing('0');
|
||
|
|
||
|
}
|
||
|
void boundingRect() {
|
||
|
QFont font("Arial", 18);
|
||
|
font.setStyleStrategy(QFont::NoAntialias);
|
||
|
QFontMetricsF metric(font);
|
||
|
qDebug()<<"boundingRect";
|
||
|
QRectF rrr(0,0,50,100);
|
||
|
auto text = "aaa aa";
|
||
|
qDebug()<<metric.boundingRect(rrr, Qt::TextWordWrap, text);
|
||
|
qDebug()<<metric.boundingRect(rrr, Qt::TextWrapAnywhere, text);
|
||
|
qDebug()<<metric.boundingRect(rrr, Qt::TextWordWrap | Qt::TextWrapAnywhere, text);
|
||
|
|
||
|
}
|
||
|
#include <QLabel>
|
||
|
#include <QScrollArea>
|
||
|
class TestWin : public QWidget {
|
||
|
public:
|
||
|
TestWin(){
|
||
|
resize(400, 100);
|
||
|
auto hBox = new QHBoxLayout(this);
|
||
|
hBox->setContentsMargins(100,0,0,0);
|
||
|
aaa = new QLabel("Aaaaaaaaaaaaaaaaaaaaaaaa");
|
||
|
aaa->setAutoFillBackground(true);
|
||
|
QPalette pal;
|
||
|
pal.setColor(QPalette::Window, Qt::darkGreen);
|
||
|
aaa->setPalette(pal);
|
||
|
aaa->setMinimumWidth(10);
|
||
|
hBox->addWidget(aaa);
|
||
|
|
||
|
bbb = new QLabel("B");
|
||
|
bbb->setAutoFillBackground(true);
|
||
|
pal.setColor(QPalette::Window, Qt::darkCyan);
|
||
|
bbb->setPalette(pal);
|
||
|
bbb->setMinimumWidth(1);
|
||
|
|
||
|
auto poli = aaa->sizePolicy();
|
||
|
poli.setHorizontalPolicy(QSizePolicy::Expanding);
|
||
|
aaa->setSizePolicy(poli);
|
||
|
bbb->setSizePolicy(poli);
|
||
|
|
||
|
|
||
|
hBox->addWidget(bbb);
|
||
|
}
|
||
|
void mouseDoubleClickEvent(QMouseEvent *) override {
|
||
|
qDebug()<<"sizeHint "<<aaa->sizeHint()<<bbb->sizeHint();
|
||
|
qDebug()<<"minHint "<<aaa->minimumSizeHint()<<bbb->minimumSizeHint();
|
||
|
qDebug()<<"sizePolicy"<<aaa->sizePolicy()<<bbb->sizePolicy();
|
||
|
qDebug()<<"minSize "<<aaa->minimumSize()<<bbb->minimumSize();
|
||
|
qDebug()<<"maxSize "<<aaa->maximumSize()<<bbb->maximumSize();
|
||
|
qDebug()<<"size "<<aaa->size()<<bbb->size();
|
||
|
}
|
||
|
QWidget *aaa;
|
||
|
QWidget *bbb;
|
||
|
};
|
||
|
int tttmain(int argc, char *argv[]) {
|
||
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||
|
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||
|
QApplication a(argc, argv);
|
||
|
QFont font = a.font();
|
||
|
font.setPointSize(14);
|
||
|
a.setFont(font);
|
||
|
|
||
|
TestWin w;
|
||
|
w.show();
|
||
|
return a.exec();
|
||
|
}
|
||
|
|