696 edit2.setReadOnly(true); |
696 edit2.setReadOnly(true); |
697 edit2.setStyleSheet("QLineEdit { font-size: 24pt; } QLineEdit:read-only { font-size: 26pt; }"); |
697 edit2.setStyleSheet("QLineEdit { font-size: 24pt; } QLineEdit:read-only { font-size: 26pt; }"); |
698 QCOMPARE(FONTSIZE(edit2), 26); |
698 QCOMPARE(FONTSIZE(edit2), 26); |
699 } |
699 } |
700 |
700 |
701 static bool testForColors(const QImage& image, const QColor& color) |
701 // Ensure primary will only return true if the color covers more than 50% of pixels |
|
702 static bool testForColors(const QImage& image, const QColor& color, bool ensurePrimary=false) |
702 { |
703 { |
703 int count = 0; |
704 int count = 0; |
704 QRgb rgb = color.rgba(); |
705 QRgb rgb = color.rgba(); |
|
706 int totalCount = image.height()*image.width(); |
705 for (int y = 0; y < image.height(); ++y) { |
707 for (int y = 0; y < image.height(); ++y) { |
706 for (int x = 0; x < image.width(); ++x) { |
708 for (int x = 0; x < image.width(); ++x) { |
707 // Because of antialiasing we allow a certain range of errors here. |
709 // Because of antialiasing we allow a certain range of errors here. |
708 QRgb pixel = image.pixel(x, y); |
710 QRgb pixel = image.pixel(x, y); |
|
711 |
709 if (qAbs((int)(pixel & 0xff) - (int)(rgb & 0xff)) + |
712 if (qAbs((int)(pixel & 0xff) - (int)(rgb & 0xff)) + |
710 qAbs((int)((pixel & 0xff00) >> 8) - (int)((rgb & 0xff00) >> 8)) + |
713 qAbs((int)((pixel & 0xff00) >> 8) - (int)((rgb & 0xff00) >> 8)) + |
711 qAbs((int)((pixel & 0xff0000) >> 16) - (int)((rgb & 0xff0000) >> 16)) <= 50) { |
714 qAbs((int)((pixel & 0xff0000) >> 16) - (int)((rgb & 0xff0000) >> 16)) <= 50) { |
712 if (++count >= 10) { |
715 count++; |
|
716 if (!ensurePrimary && count >=10 ) |
713 return true; |
717 return true; |
714 } |
718 else if (count > totalCount/2) |
|
719 return true; |
715 } |
720 } |
716 } |
721 } |
717 } |
722 } |
718 |
723 |
719 return false; |
724 return false; |
1526 |
1531 |
1527 tree.setEnabled(true); |
1532 tree.setEnabled(true); |
1528 tree.render(&image); |
1533 tree.render(&image); |
1529 QVERIFY(testForColors(image, tree.palette().base().color())); |
1534 QVERIFY(testForColors(image, tree.palette().base().color())); |
1530 QVERIFY(!testForColors(image, QColor(0xab, 0x12, 0x51))); |
1535 QVERIFY(!testForColors(image, QColor(0xab, 0x12, 0x51))); |
|
1536 |
|
1537 QTableWidget table(12, 12); |
|
1538 table.setItem(0, 0, new QTableWidgetItem()); |
|
1539 table.setStyleSheet( "QTableView {background-color: #ff0000}" ); |
|
1540 table.show(); |
|
1541 QTest::qWait(20); |
|
1542 image = QImage(table.width(), table.height(), QImage::Format_ARGB32); |
|
1543 table.render(&image); |
|
1544 QVERIFY(testForColors(image, Qt::red, true)); |
1531 } |
1545 } |
1532 |
1546 |
1533 void tst_QStyleSheetStyle::task232085_spinBoxLineEditBg() |
1547 void tst_QStyleSheetStyle::task232085_spinBoxLineEditBg() |
1534 { |
1548 { |
1535 // This test is a simplified version of the focusColors() test above. |
1549 // This test is a simplified version of the focusColors() test above. |