forked from PinappleUnderTheSea/os223
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwidget.cpp
53 lines (47 loc) · 1.48 KB
/
mainwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "mainwidget.h"
//#include <DFontSizeManager>
//#include <DGuiApplicationHelper>
//DGUI_USE_NAMESPACE
MainWidget::MainWidget()
{
//setMinimumSize(5,5);
//设置等宽字体
font.setFamily("Noto Mono");
// 获取dpi,一般默认都是96,根据dpi进行字体的缩放,直接设置pointsize无法解决hidpi问题
dpi = QApplication::primaryScreen()->logicalDotsPerInch();
qDebug()<<"!!创建新的文字ui";
Label=new QLabel();
Label->setAlignment(Qt::AlignCenter);
font.setPixelSize((dpi*9)/72);
Label->setFont(font);
QString style;
style=QString("QLabel {color: %1;}").arg("#000");
Label->setStyleSheet(style);
Label->setVisible(true);
Label->setText(QString("SELF_STARTUP"));
centralLayout = new QBoxLayout(QBoxLayout::LeftToRight);
centralLayout->addWidget(Label);
centralLayout->setMargin(0);
centralLayout->setSpacing(4);
setLayout(centralLayout);
qDebug()<<"out mainwidget";
}
MainWidget::~MainWidget()
{
if(centralLayout!=NULL)
{
delete centralLayout;
centralLayout=NULL;
}
}
QSize MainWidget::sizeHint() const
{
if(centralLayout==NULL)return QSize(100,30);
int w,h;
w=QFontMetrics(font).boundingRect(QString("SELF_STARTUP")).size().width();
h=QFontMetrics(font).boundingRect(QString("SELF_STARTUP")).size().height();
QSize size(w,h);
//qDebug()<<size;
//qDebug()<<QString("width:%1 height:%2").arg(width()).arg(height());
return size;
}