测试适配效果ok1

qt6
zcy 2022-04-10 02:54:04 +08:00
parent 7e465c3ab4
commit 3daad474a6
1 changed files with 85 additions and 8 deletions

93
Qss.cpp
View File

@ -25,6 +25,12 @@
#include <QGraphicsDropShadowEffect>
#include <QPainterPath>
#include <QAction>
#include <QPushButton>
#include <QLineEdit>
#include <QComboBox>
#include <QDateTimeEdit>
#include <QMenu>
#include <QMenuBar>
#define QSSDIALOG_SHADOW_WIDTH 12
#define QSSDIALOG_BODER_WIDTH 0
@ -346,12 +352,20 @@ QssMainWindow::~QssMainWindow()
void QssMainWindow::AdapteDpi()
{
QObjectList child = this->children();
QObjectList child = this->m_frame->children();
int i = 0;
for(int i = 0;i < child.size();i++){
qDebug()<<child.at(i)->objectName() + " "
+ child.at(i)->metaObject()->className();
// QssTtitleBar
if(child.at(i)->objectName() =="qssTitleBar"){
QssTtitleBar *p = dynamic_cast<QssTtitleBar*>(child.at(i));
if(nullptr != p){
qDebug()<< p->sizePolicy();
p->setFixedHeight(p->height()*m_dpi_ratio);
}
}
if(child.at(i)->children().size() > 0){
this->rangeObjectList(child.at(i),i + 1);
}
@ -609,7 +623,9 @@ void QssMainWindow::dpiScaleChildren()
void QssMainWindow::detectDpi()
{
m_dpi_ratio = this->logicalDpiX() / 96;
int logicdpi = logicalDpiX();
m_dpi_ratio = this->logicalDpiX() / 96.0;
}
void QssMainWindow::rangeObjectList(QObject *obj, int indent)
@ -622,23 +638,84 @@ void QssMainWindow::rangeObjectList(QObject *obj, int indent)
for(int i = 0;i < child.size();i++){
qDebug()<<tmp + child.at(i)->objectName() + " " +
child.at(i)->metaObject()->className();
if(child.at(i)->metaObject()->className() =="QAction"){
QAction *p = dynamic_cast<QAction*>(child.at(i));
if(nullptr != p){
if(child.at(i)->metaObject()->className() =="QssTtitleBar"){
QssTtitleBar *p = dynamic_cast<QssTtitleBar*>(child.at(i));
if(nullptr != p){
p->setMinimumSize(p->width()*m_dpi_ratio,
p->height()*m_dpi_ratio);
}
}
if(child.at(i)->metaObject()->className() =="QMenuBar"){
QMenuBar *p = dynamic_cast<QMenuBar*>(child.at(i));
if(nullptr != p){
p->setMinimumSize(p->width()*m_dpi_ratio,
p->height()*m_dpi_ratio);
}
continue;
}
if(child.at(i)->metaObject()->className() =="QDateTimeEdit"){
QDateTimeEdit *p = dynamic_cast<QDateTimeEdit*>(child.at(i));
if(nullptr != p){
p->setMinimumSize(p->minimumHeight()*m_dpi_ratio,
p->minimumHeight()*m_dpi_ratio);
}
continue;
}
if(strcmp(child.at(i)->metaObject()->className(),"QLabel") == 0){
QLabel *p = dynamic_cast<QLabel*>(child.at(i));
if(nullptr != p){
p->setFixedHeight(p->height()*this->m_dpi_ratio);
qDebug()<< "parent is "
<< p->parent()->metaObject()->className();
if(p->parent() != nullptr){
QWidget *wparent = dynamic_cast<QWidget*> (p->parent());
if(nullptr != wparent){
if(nullptr != wparent->layout()){
qDebug()<< "index of label in layout is "
<<wparent->layout()->indexOf(p);
}
}
}
QFont pf = p->font();
pf.setPointSize(pf.pointSize()*this->m_dpi_ratio);
p->setFont(pf);
p->setMinimumSize(p->minimumHeight()*m_dpi_ratio,
p->minimumHeight()*m_dpi_ratio);
}
continue;
}
if(child.at(i)->metaObject()->className() =="QLabel"){
QLabel *p = dynamic_cast<QLabel*>(child.at(i));
if(strcmp(child.at(i)->metaObject()->className(),"QComboBox") == 0){
QComboBox *p = dynamic_cast<QComboBox*>(child.at(i));
p->setMinimumSize(p->width()*m_dpi_ratio,
p->height()*m_dpi_ratio);
continue;
}
if(strcmp(child.at(i)->metaObject()->className(),"QPushButton") == 0){
QPushButton *p = dynamic_cast<QPushButton*>(child.at(i));
qDebug()<<tmp + child.at(i)->objectName() + " " +
child.at(i)->metaObject()->className() << p->size();
if(nullptr != p){
p->setFixedHeight(p->height()*m_dpi_ratio);
p->setMinimumWidth(p->width()*m_dpi_ratio);
}
continue;
}
if(strcmp(child.at(i)->metaObject()->className(),"QLineEdit") == 0){
QLineEdit *p = dynamic_cast<QLineEdit*>(child.at(i));
if(nullptr != p){
p->setFixedHeight(p->height()*this->m_dpi_ratio);
QFont pf = p->font();
}
continue;
}
if(child.at(i)->children().size() > 0){