问题
I'm using Qt 4.7 and trying to apply Qt stylesheets to my application. As mentioned here with the help of border-image you can stretch image with corners left "as is". Here is a good example of how that should work. Unfortunately I'm unable to get the same result. Instead of preserved corners I'm getting cutted and repeated middle part of the image. Is there any mistakes in my code or its not implemented in Qt? (button added to MainWindow via gui designer).
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setStyleSheet( "QPushButton{ border-image: url(:/border-image-marked.png) 25 30 10 20 repeat repeat; }" );
MainWindow w;
w.show();
return a.exec();
}
Image taken from example above. Direct link to it.
p.s. It works well in QML's BorderImage.
回答1:
You're trying to apply your styleSheet to a non-present QPushButton.
According to http://qt-project.org/doc/qt-4.8/stylesheet-reference.html#border-image-prop only the following elements support this CSS property:
This property is supported by QAbstractItemView subclasses, QAbstractSpinBox subclasses, QCheckBox, QComboBox, QFrame, QGroupBox, QLabel, QLineEdit, QMenu, QMenuBar, QPushButton, QRadioButton, QSplitter, QTextEdit and QToolTip.
来源:https://stackoverflow.com/questions/11969877/preserving-corners-while-stretching-border-image-usging-qt-stylesheet