Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <a href="http://doc.qt.nokia.com/stable/widgets-stylesheet.html" rel="nofollow">Style Sheet example</a> that comes with Qt has everything you need to see how this is done. Look in your Qt SDK folder for something like <code>QtSDK\Examples\4.7\widgets\stylesheet</code>.</p> <p><strong>Update:</strong></p> <p>When you run that example program, you can use the <code>File</code> menu and select <code>Edit Style...</code> to edit the active style sheet. Choose the <code>Pagefold</code> style. Back at the main screen you will notice that the <code>OK</code> and <code>Cancel</code> buttons are using multiple images for the up, down and hover states.</p> <p>These states map to the images in <code>QtSDK\Examples\4.7\widgets\stylesheet\images</code> directory: <code>pushbutton.png</code>, <code>pushbutton_pressed.png</code>, and <code>pushbutton_hover.png</code> respectively.</p> <p>The style sheet for mapping these images to the buttons is <code>QtSDK\Examples\4.7\widgets\stylesheet\pagefold.qss</code>. It's possible that Qt's unfortunate convention of using <code>.qss</code> as a file extension for stylesheets is confusing you.</p> <p>In here you will find the following relevant selectors:</p> <pre><code>QPushButton, QComboBox[editable="false"], QComboBox[editable="true"]::drop-down { border-image: url(:/images/pushbutton.png) 5; border-width: 5; } QPushButton:hover, QComboBox[editable="false"]:hover, QComboBox[editable="true"]::drop-down:hover, QMenuBar::item:hover { border-image: url(:/images/pushbutton_hover.png) 5; border-width: 5; } QPushButton:pressed, QComboBox[editable="false"]:on, QComboBox[editable="true"]::drop-down:on, QMenuBar::item:on { border-image: url(:/images/pushbutton_pressed.png) 5; border-width: 5; } </code></pre> <p>The button images are referenced using the path prefix <code>:/</code> which corresponds to images stored in a Qt resource file. It is not necessary for the images to be compiled into a resource. They could also be identified by absolute or relative file paths.</p> <p>To have these style sheets take effect, they need to be loaded into a <code>QString</code> and assigned to the application object or some widget in the parent hierarchy of your target buttons. In the example program, the code that does this is in the <code>loadStyleSheet()</code> method:</p> <pre><code>void StyleSheetEditor::loadStyleSheet(const QString &amp;sheetName) { QFile file(":/qss/" + sheetName.toLower() + ".qss"); file.open(QFile::ReadOnly); QString styleSheet = QLatin1String(file.readAll()); ui.styleTextEdit-&gt;setPlainText(styleSheet); qApp-&gt;setStyleSheet(styleSheet); ui.applyButton-&gt;setEnabled(false); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload