tst_QStyleSheetStyle: Pass on High DPI screens

The test requires High DPI scaling to be disabled since it
manipulates the factors itself in a test.

Turn it off initially and introduce a member variable
containing a suitable size depending on the screen to make the
test pass on High DPI screens without violating minimum window
widths on Windows.

Task-number: QTBUG-76493
Change-Id: I7b908940413d6a35a4bee781b4df07a31069bb17
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Friedemann Kleint 2019-08-15 13:24:11 +02:00 committed by Edward Welbourne
parent 0a1f48a082
commit 194d4946c7

View File

@ -72,6 +72,8 @@ class tst_QStyleSheetStyle : public QObject
public: public:
tst_QStyleSheetStyle(); tst_QStyleSheetStyle();
static void initMain();
private slots: private slots:
void init(); void init();
void cleanup(); void cleanup();
@ -166,10 +168,22 @@ private:
} }
static int APPFONTSIZE(const QWidget &w) { return QApplication::font(&w).pointSize(); } static int APPFONTSIZE(const QWidget &w) { return QApplication::font(&w).pointSize(); }
const QRect m_availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
QSize m_testSize;
}; };
// highdpiImages() tests HighDPI scaling; disable initially.
void tst_QStyleSheetStyle::initMain()
{
QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
}
tst_QStyleSheetStyle::tst_QStyleSheetStyle() tst_QStyleSheetStyle::tst_QStyleSheetStyle()
{ {
const int testSize = qMax(200, m_availableGeometry.width() / 10);
m_testSize.setWidth(testSize);
m_testSize.setHeight(testSize);
} }
void tst_QStyleSheetStyle::init() void tst_QStyleSheetStyle::init()
@ -187,7 +201,7 @@ void tst_QStyleSheetStyle::numinstances()
{ {
QWidget w; QWidget w;
w.setWindowTitle(QTest::currentTestFunction()); w.setWindowTitle(QTest::currentTestFunction());
w.resize(200, 200); w.resize(m_testSize);
centerOnScreen(&w); centerOnScreen(&w);
QCommonStyle *style = new QCommonStyle; QCommonStyle *style = new QCommonStyle;
style->setParent(&w); style->setParent(&w);
@ -410,6 +424,7 @@ void tst_QStyleSheetStyle::repolish_without_crashing()
{ {
// This used to crash, QTBUG-69204 // This used to crash, QTBUG-69204
QMainWindow w; QMainWindow w;
w.resize(m_testSize);
w.setWindowTitle(QTest::currentTestFunction()); w.setWindowTitle(QTest::currentTestFunction());
QScopedPointer<QSplitter> splitter1(new QSplitter(w.centralWidget())); QScopedPointer<QSplitter> splitter1(new QSplitter(w.centralWidget()));
QScopedPointer<QSplitter> splitter2(new QSplitter); QScopedPointer<QSplitter> splitter2(new QSplitter);
@ -619,13 +634,13 @@ void tst_QStyleSheetStyle::dynamicProperty()
QString appStyle = QApplication::style()->metaObject()->className(); QString appStyle = QApplication::style()->metaObject()->className();
QPushButton pb1(QStringLiteral("dynamicProperty_pb1")); QPushButton pb1(QStringLiteral("dynamicProperty_pb1"));
pb1.setMinimumWidth(160); pb1.setMinimumWidth(m_testSize.width());
pb1.move(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(20, 100)); pb1.move(m_availableGeometry.topLeft() + QPoint(20, 100));
QPushButton pb2(QStringLiteral("dynamicProperty_pb2")); QPushButton pb2(QStringLiteral("dynamicProperty_pb2"));
pb2.setWindowTitle(QTest::currentTestFunction()); pb2.setWindowTitle(QTest::currentTestFunction());
pb2.setMinimumWidth(160); pb2.setMinimumWidth(m_testSize.width());
pb2.move(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(20, 200)); pb2.move(m_availableGeometry.topLeft() + QPoint(20, m_testSize.width() + 40));
pb1.setProperty("type", "critical"); pb1.setProperty("type", "critical");
qApp->setStyleSheet("*[class~=\"QPushButton\"] { color: red; } *[type=\"critical\"] { background: white; }"); qApp->setStyleSheet("*[class~=\"QPushButton\"] { color: red; } *[type=\"critical\"] { background: white; }");
@ -831,7 +846,7 @@ void tst_QStyleSheetStyle::fontPrecedence()
{ {
QLineEdit edit; QLineEdit edit;
edit.setWindowTitle(QTest::currentTestFunction()); edit.setWindowTitle(QTest::currentTestFunction());
edit.setMinimumWidth(200); edit.setMinimumWidth(m_testSize.width());
centerOnScreen(&edit); centerOnScreen(&edit);
edit.show(); edit.show();
QFont font; QFont font;
@ -1066,24 +1081,25 @@ void tst_QStyleSheetStyle::background()
const QString styleSheet = QStringLiteral("* { background-color: #e8ff66; }"); const QString styleSheet = QStringLiteral("* { background-color: #e8ff66; }");
QVector<WidgetPtr> widgets; QVector<WidgetPtr> widgets;
const QPoint topLeft = QGuiApplication::primaryScreen()->availableGeometry().topLeft(); const QPoint topLeft = m_availableGeometry.topLeft();
// Testing inheritance styling of QDialog. // Testing inheritance styling of QDialog.
WidgetPtr toplevel(new SingleInheritanceDialog); WidgetPtr toplevel(new SingleInheritanceDialog);
toplevel->resize(200, 200); toplevel->resize(m_testSize);
toplevel->move(topLeft + QPoint(20, 20)); toplevel->move(topLeft + QPoint(20, 20));
toplevel->setStyleSheet(styleSheet); toplevel->setStyleSheet(styleSheet);
widgets.append(toplevel); widgets.append(toplevel);
toplevel = WidgetPtr(new DoubleInheritanceDialog); toplevel = WidgetPtr(new DoubleInheritanceDialog);
toplevel->resize(200, 200); toplevel->resize(m_testSize);
toplevel->move(topLeft + QPoint(20, 320)); toplevel->move(topLeft + QPoint(20, m_testSize.height() + 120));
toplevel->setStyleSheet(styleSheet); toplevel->setStyleSheet(styleSheet);
widgets.append(toplevel); widgets.append(toplevel);
// Testing gradients in QComboBox. // Testing gradients in QComboBox.
// First color // First color
toplevel = WidgetPtr(new QDialog); toplevel = WidgetPtr(new QDialog);
toplevel->move(topLeft + QPoint(320, 20)); toplevel->resize(m_testSize);
toplevel->move(topLeft + QPoint(m_testSize.width() + 120, 20));
QGridLayout *layout = new QGridLayout(toplevel.data()); QGridLayout *layout = new QGridLayout(toplevel.data());
QComboBox* cb = new QComboBox; QComboBox* cb = new QComboBox;
cb->setMinimumWidth(160); cb->setMinimumWidth(160);
@ -1092,7 +1108,8 @@ void tst_QStyleSheetStyle::background()
widgets.append(toplevel); widgets.append(toplevel);
// Second color // Second color
toplevel = WidgetPtr(new QDialog); toplevel = WidgetPtr(new QDialog);
toplevel->move(topLeft + QPoint(320, 320)); toplevel->resize(m_testSize);
toplevel->move(topLeft + QPoint(m_testSize.width() + 120, m_testSize.height() + 120));
layout = new QGridLayout(toplevel.data()); layout = new QGridLayout(toplevel.data());
cb = new QComboBox; cb = new QComboBox;
cb->setMinimumWidth(160); cb->setMinimumWidth(160);
@ -1186,6 +1203,7 @@ void tst_QStyleSheetStyle::attributesList()
void tst_QStyleSheetStyle::minmaxSizes() void tst_QStyleSheetStyle::minmaxSizes()
{ {
QTabWidget tabWidget; QTabWidget tabWidget;
tabWidget.resize(m_testSize);
tabWidget.setWindowTitle(QTest::currentTestFunction()); tabWidget.setWindowTitle(QTest::currentTestFunction());
tabWidget.setObjectName("tabWidget"); tabWidget.setObjectName("tabWidget");
int index1 = tabWidget.addTab(new QLabel("Tab1"),"a"); int index1 = tabWidget.addTab(new QLabel("Tab1"),"a");
@ -1226,6 +1244,7 @@ void tst_QStyleSheetStyle::task206238_twice()
{ {
const QColor red(Qt::red); const QColor red(Qt::red);
QMainWindow w; QMainWindow w;
w.resize(m_testSize);
w.setWindowTitle(QTest::currentTestFunction()); w.setWindowTitle(QTest::currentTestFunction());
QTabWidget* tw = new QTabWidget; QTabWidget* tw = new QTabWidget;
tw->addTab(new QLabel("foo"), "test"); tw->addTab(new QLabel("foo"), "test");
@ -1403,7 +1422,7 @@ void tst_QStyleSheetStyle::proxyStyle()
QString styleSheet("QPushButton {background-color: red; }"); QString styleSheet("QPushButton {background-color: red; }");
QWidget *w = new QWidget; QWidget *w = new QWidget;
w->setMinimumWidth(160); w->setMinimumWidth(m_testSize.width());
centerOnScreen(w); centerOnScreen(w);
QVBoxLayout *layout = new QVBoxLayout(w); QVBoxLayout *layout = new QVBoxLayout(w);
@ -1522,6 +1541,7 @@ void tst_QStyleSheetStyle::toolTip()
{ {
qApp->setStyleSheet(QString()); qApp->setStyleSheet(QString());
QWidget w; QWidget w;
w.resize(m_testSize);
w.setWindowTitle(QTest::currentTestFunction()); w.setWindowTitle(QTest::currentTestFunction());
// Use "Fusion" to prevent the Vista style from clobbering the tooltip palette in polish(). // Use "Fusion" to prevent the Vista style from clobbering the tooltip palette in polish().
QStyle *fusionStyle = QStyleFactory::create(QLatin1String("Fusion")); QStyle *fusionStyle = QStyleFactory::create(QLatin1String("Fusion"));
@ -1601,8 +1621,8 @@ void tst_QStyleSheetStyle::embeddedFonts()
//task 235622 and 210551 //task 235622 and 210551
QSpinBox spin; QSpinBox spin;
spin.setWindowTitle(QTest::currentTestFunction()); spin.setWindowTitle(QTest::currentTestFunction());
spin.setMinimumWidth(160); spin.setMinimumWidth(m_testSize.width());
spin.move(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(20, 20)); spin.move(m_availableGeometry.topLeft() + QPoint(20, 20));
spin.show(); spin.show();
spin.setStyleSheet("QSpinBox { font-size: 32px; }"); spin.setStyleSheet("QSpinBox { font-size: 32px; }");
QTest::qWait(20); QTest::qWait(20);
@ -1623,7 +1643,7 @@ void tst_QStyleSheetStyle::embeddedFonts()
//task 242556 //task 242556
QComboBox box; QComboBox box;
box.setMinimumWidth(160); box.setMinimumWidth(160);
box.move(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(20, 120)); box.move(m_availableGeometry.topLeft() + QPoint(20, 120));
box.setEditable(true); box.setEditable(true);
box.addItems(QStringList() << "First" << "Second" << "Third"); box.addItems(QStringList() << "First" << "Second" << "Third");
box.setStyleSheet("QComboBox { font-size: 32px; }"); box.setStyleSheet("QComboBox { font-size: 32px; }");
@ -1720,7 +1740,7 @@ void tst_QStyleSheetStyle::task188195_baseBackground()
QTreeView tree; QTreeView tree;
tree.setWindowTitle(QTest::currentTestFunction()); tree.setWindowTitle(QTest::currentTestFunction());
tree.setStyleSheet( "QTreeView:disabled { background-color:#ab1251; }" ); tree.setStyleSheet( "QTreeView:disabled { background-color:#ab1251; }" );
tree.move(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(20, 100)); tree.setGeometry(QRect(m_availableGeometry.topLeft() + QPoint(20, 100), m_testSize));
tree.show(); tree.show();
QVERIFY(QTest::qWaitForWindowActive(&tree)); QVERIFY(QTest::qWaitForWindowActive(&tree));
QImage image(tree.width(), tree.height(), QImage::Format_ARGB32); QImage image(tree.width(), tree.height(), QImage::Format_ARGB32);
@ -1741,7 +1761,8 @@ void tst_QStyleSheetStyle::task188195_baseBackground()
QTableWidget table(12, 12); QTableWidget table(12, 12);
table.setItem(0, 0, new QTableWidgetItem()); table.setItem(0, 0, new QTableWidgetItem());
table.setStyleSheet( "QTableView {background-color: #ff0000}" ); table.setStyleSheet( "QTableView {background-color: #ff0000}" );
table.move(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(300, 100)); // This needs to be large so that >50% (excluding header rows/columns) are red.
table.setGeometry(QRect(m_availableGeometry.topLeft() + QPoint(300, 100), m_testSize * 2));
table.show(); table.show();
QVERIFY(QTest::qWaitForWindowActive(&table)); QVERIFY(QTest::qWaitForWindowActive(&table));
image = QImage(table.width(), table.height(), QImage::Format_ARGB32); image = QImage(table.width(), table.height(), QImage::Format_ARGB32);
@ -1834,10 +1855,10 @@ void tst_QStyleSheetStyle::QTBUG11658_cachecrash()
class Widget : public QWidget class Widget : public QWidget
{ {
public: public:
Widget(QWidget *parent = nullptr) Widget(int minimumWidth, QWidget *parent = nullptr)
: QWidget(parent) : QWidget(parent)
{ {
setMinimumWidth(160); setMinimumWidth(minimumWidth);
QVBoxLayout* pLayout = new QVBoxLayout(this); QVBoxLayout* pLayout = new QVBoxLayout(this);
QCheckBox* pCheckBox = new QCheckBox(this); QCheckBox* pCheckBox = new QCheckBox(this);
pLayout->addWidget(pCheckBox); pLayout->addWidget(pCheckBox);
@ -1849,9 +1870,9 @@ void tst_QStyleSheetStyle::QTBUG11658_cachecrash()
} }
}; };
Widget *w = new Widget(); Widget *w = new Widget(m_testSize.width());
delete w; delete w;
w = new Widget(); w = new Widget(m_testSize.width());
w->setWindowTitle(QTest::currentTestFunction()); w->setWindowTitle(QTest::currentTestFunction());
centerOnScreen(w); centerOnScreen(w);
w->show(); w->show();
@ -1888,6 +1909,7 @@ void tst_QStyleSheetStyle::QTBUG36933_brokenPseudoClassLookup()
const int columnCount = 10; const int columnCount = 10;
QTableWidget widget(rowCount, columnCount); QTableWidget widget(rowCount, columnCount);
widget.resize(m_testSize);
widget.setWindowTitle(QTest::currentTestFunction()); widget.setWindowTitle(QTest::currentTestFunction());
for (int row = 0; row < rowCount; ++row) { for (int row = 0; row < rowCount; ++row) {
@ -1927,12 +1949,12 @@ void tst_QStyleSheetStyle::styleSheetChangeBeforePolish()
widget.setWindowTitle(QTest::currentTestFunction()); widget.setWindowTitle(QTest::currentTestFunction());
QVBoxLayout *vbox = new QVBoxLayout(&widget); QVBoxLayout *vbox = new QVBoxLayout(&widget);
QFrame *frame = new QFrame(&widget); QFrame *frame = new QFrame(&widget);
frame->setFixedSize(200, 200); frame->setFixedSize(m_testSize);
frame->setStyleSheet("background-color: #FF0000;"); frame->setStyleSheet("background-color: #FF0000;");
frame->setStyleSheet("background-color: #00FF00;"); frame->setStyleSheet("background-color: #00FF00;");
vbox->addWidget(frame); vbox->addWidget(frame);
QFrame *frame2 = new QFrame(&widget); QFrame *frame2 = new QFrame(&widget);
frame2->setFixedSize(200, 200); frame2->setFixedSize(m_testSize);
frame2->setStyleSheet("background-color: #FF0000;"); frame2->setStyleSheet("background-color: #FF0000;");
frame2->setStyleSheet("background-color: #00FF00;"); frame2->setStyleSheet("background-color: #00FF00;");
vbox->addWidget(frame); vbox->addWidget(frame);