Preserving corners while stretching border image usging qt stylesheet

冷暖自知 提交于 2019-12-13 17:20:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!