here OS의 정의의 전체 목록을 찾을 수
#ifdef Q_OS_MAC
// change font here
#endif
:
2) 사용은, 슬프게도, 당 플랫폼으로 그것을 할 ifdefs Win32에서 Mac OS X로, 특히 :
a) 버튼 : 높이 (픽셀 단위)는 동일하게 보이기 위해 달라야합니다.
b) 레이블 : 글꼴 크기는 (포인트 단위로) 동일하게보기 위해 달라야합니다.
나는이 규칙에 따라, -as possible- 일반적인 솔루션을 만들려고 : 나는 단지 하나 개의 환경 (윈도우 XP)의 모든 형태와 위젯 레이아웃 편집을 수행하고 다른 소스를 옮겼다
- (OS X) 컴파일에만 & 테스트.
- 내가 (노호 참조) 버튼의 높이 및 런타임에 레이블의 글꼴 크기를 수정하는 일반적인 OS-Dependend 기능을 생성하고이 같은 setupUI() 후, 모든 사용자 정의 대화 생성자에서이 함수를 호출 :
someDialog :: someDialog (QWidget * parent) : QDialog (부모)
{
setupUi (this);
genAdjustWidgetAppearanceToOS (this);
// ...
}
나는 (아무 것도 완벽하지 않음) 내가 영향을 싶지 않을 것 모든 컨트롤의 이름을 genAdjustWidgetAppearanceToOS (이) 함수 에서 예외 목록을 소개하고 그 안에 넣어. 을 (:
는 여기를 확인하고 당신에게 어떤 도움이 될 수 있는지 내 일반적인 기능입니다!적어도 "DoNotAffect"목록을 수정하고 레이블/단추 이름을 추가해야 함)
// ======================================================
// Adjust specific Widget children according to O/S
// => Set Buttons height
// => Set labels font size
// ======================================================
void genAdjustWidgetAppearanceToOS(QWidget *rootWidget)
{
if (rootWidget == NULL)
return;
QObject *child = NULL;
QObjectList Containers;
QObject *container = NULL;
QStringList DoNotAffect;
// Make an exception list (Objects not to be affected)
DoNotAffect.append("aboutTitleLabel"); // about Dialog
DoNotAffect.append("aboutVersionLabel"); // about Dialog
DoNotAffect.append("aboutCopyrightLabel"); // about Dialog
DoNotAffect.append("aboutUrlLabel"); // about Dialog
DoNotAffect.append("aboutLicenseLabel"); // about Dialog
// Set sizes according to OS:
#ifdef Q_OS_MAC
int ButtonHeight = 32;
int LabelsFontSize = 12;
#else // Win XP/7
int ButtonHeight = 22;
int LabelsFontSize = 8;
#endif
// Append root to containers
Containers.append(rootWidget);
while (!Containers.isEmpty())
{
container = Containers.takeFirst();
if (container != NULL)
{
for (int ChIdx=0; ChIdx < container->children().size(); ChIdx++)
{
child = container->children()[ChIdx];
if (!child->isWidgetType() || DoNotAffect.contains(child->objectName()))
continue;
// Append containers to Stack for recursion
if (child->children().size() > 0)
Containers.append(child);
else
{
// Cast child object to button and label
// (if the object is not of the correct type, it will be NULL)
QPushButton *button = qobject_cast<QPushButton *>(child);
QLabel *label = qobject_cast<QLabel *>(child);
if (button != NULL)
{
button->setMinimumHeight(ButtonHeight); // Win
button->setMaximumHeight(ButtonHeight); // Win
button->setSizePolicy(QSizePolicy::Fixed,
button->sizePolicy().horizontalPolicy());
}
else if (label != NULL)
{
QFont aFont = label->font();
aFont.setPointSize(LabelsFontSize);
label->setFont(aFont);
}
}
}
}
}
}
안녕하세요. 답장을 보내 주셔서 감사합니다. 어떤 식 으로든 글꼴을 변경하지 않고 대신 대화 상자 자체의 크기를 늘리는 것이 가능한지 궁금합니다. 플랫폼에 종속적 인 .ui 파일을 만들 수는 있지만 많은 대화 상자가 있으며 가능하다면 좀 더 우아한 것을 선호합니다. 감사. – Robin
대화 상자에서 setSize()를 호출하여 크기를 간단하게 늘릴 수 있습니까? –