Qt designer Qt设计器:无法更改字体大小

Qt designer Qt设计器:无法更改字体大小,qt-designer,Qt Designer,我在选项卡上有一些标签(即tabWidget),当我更改fontsize时,它确实会更改,但当我保存文件时,它们都会切换回其他标签(默认或其他)。 这是怎么回事 我认为您需要使用样式表设置字体。不久前,我在寻找信息,通过阅读Qt文档和使用一些官方Qt示例,我找到了一个解决方案 这里有一个例子。根据您自己的要求更改css .pro文件 HEADERS = mainwindow.h FORMS = mainwindow.ui RESOURCES = style

我在选项卡上有一些标签(即tabWidget),当我更改fontsize时,它确实会更改,但当我保存文件时,它们都会切换回其他标签(默认或其他)。
这是怎么回事

我认为您需要使用样式表设置字体。不久前,我在寻找信息,通过阅读Qt文档和使用一些官方Qt示例,我找到了一个解决方案

这里有一个例子。根据您自己的要求更改css

.pro文件

HEADERS       = mainwindow.h 
FORMS         = mainwindow.ui 
RESOURCES     = stylesheet.qrc
SOURCES       = main.cpp \
                mainwindow.cpp \
样式表.qrc

<RCC>
<qresource prefix="/">
    <file>qss/cool.qss</file>
</qresource>
</RCC>
在这个文件中,您有比需要更多的代码,但是使用所有属性可能很重要

无论如何,您需要根据您的要求更改以下行

font: bold 14px;
检查“最小宽度”的值对于字体大小是否足够也很重要

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtWidgets>

#include "ui_mainwindow.h"

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow();

    Ui::MainWindow ui;

private:
    void loadStyleSheet(const QString &sheetName);
};

#endif
#include <QtWidgets>

#include "mainwindow.h"

MainWindow::MainWindow()
{
    ui.setupUi(this);
    loadStyleSheet("Cool");
}

void MainWindow::loadStyleSheet(const QString &sheetName)
{
    QFile file(":/qss/" + sheetName.toLower() + ".qss");
    file.open(QFile::ReadOnly);
    QString styleSheet = QString::fromLatin1(file.readAll());

    qApp->setStyleSheet(styleSheet);
}
QTabWidget::pane { /* The tab widget frame */
    border: 2px solid #C2C7CB;
}

QTabWidget::tab-bar {
    left: 5px; /* move to the right by 5px */
}

/* Style the tab using the tab sub-control. Note that
    it reads QTabBar _not_ QTabWidget */
QTabBar::tab {
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
                                stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
    border: 2px solid #C4C4C3;
    border-bottom-color: #C2C7CB; /* same as the pane color */
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    /* You should change min-width according to the
        lenght of your tab text */
    min-width: 14ex;
    padding: 4px;
    font: bold 14px;
}

QTabBar::tab:selected, QTabBar::tab:hover {
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                stop: 0 #fafafa, stop: 0.4 #f4f4f4,
                                stop: 0.5 #e7e7e7, stop: 1.0 #fafafa);
}

QTabBar::tab:selected {
    border-color: #9B9B9B;
    border-bottom-color: #C2C7CB; /* same as pane color */
}

QTabBar::tab:!selected {
    margin-top: 2px; /* make non-selected tabs look smaller */
}
font: bold 14px;