Pregunta

Estoy teniendo algunas preguntas acerca de la funcionalidad de hoja de estilo de Qt. Es realmente grande, pero se siente como que la función no es de alrededor durante mucho tiempo, sin embargo, cierto? Es de lejos la forma más fácil de peinar mi GUI sin embargo.

  1. ¿Es posible añadir la pérdida de color en las hojas de estilo? Siempre que los elementos emergentes ratón pasa por encima de un cierto flash, yo no lo quieren cambiar bruscamente color de fondo, simplemente se desvanecen en el nuevo color en 200 ms o algo así. ¿Hay una manera agradable para esto, o debe hacerse esto?

  2. En cuanto al código de
  3. ¿Puedo tener un gradiente 2D? Yo sé cómo utilizar el gradiente 1D ahora, puede cambiar de color gradualmente a lo largo de un eje (a menudo, ya sea horizontal o verticalmente). Me gustaría añadir un segundo gradiente en la parte superior de que, que tiene un tiene un bajo valor de alfa, por ejemplo. Así que si su gradiente va desde el verde (arriba) a rojo (inferior), también me gustaría que para pasar de transparente (izquierda) al blanco (derecha).

  4. Qt tiene selectores CSS para tipos (por ejemplo QPushButton) y para la identificación del (por ejemplo #mywidgetname), pero no han encontrado una forma para seleccionar o clases establecidos. Tengo un número de QFrames por ejemplo, y hasta cierto subconjunto Me gustaría añadir un estilo particular. ¿Debo nombrar mis marcos todos iguales (mismo ID)? Suena mal. Pero la selección de su tipo (QFrame) tampoco es correcto ...

Gracias!

¿Fue útil?

Solución

  1. Not using CSS that I know of. However, Qt has several nice demos using different techniques (using the animation framework), see for example the demos/examples browser.

  2. You can probably achieve what you want in #2 by using the following construction using relative coordinates of the endpoints:

    qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0.273, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255))
    

    Qt Designer has a nice editor for gradients (and for CSS in general), you may want to play with this and see what it comes up with and use that for inspiration.

  3. Not quite sure how to best solve this, but you can put multiple matches before the same rule, so you can have:

    QFrame#frame1, QFrame#frame2 { background-color: blue; }
    

Otros consejos

I know this is quite an old question, but I recently had a similar problem.

Anyway, for "3." I found you can use a "property selector" in the qss and just set the property value on the relevant widgets.

e.g. in your C++ code:

widget1->setProperty( "StyleClass", "MyCustomLAF" );
widget2->setProperty( "StyleClass", "MyCustomLAF" );

then in the qss:

QWidget[StyleClass="MyCustomLAF"] { color : purple ; }

Then any QWidget (or derived class) instance with the "StyleClass" property set to "MyCustomLAF" will have the color:purple style applied. Forgive me if the following explanation is a bit confusing or technically incorrect, but I'm implying that the property "StyleClass" is what Qt calls a "dynamic property" which (in my words) means a property that is added to a QObject instance at runtime, without being registered in the "meta stuff" using the Q_PROPERTY macro.

Also you can select all QFrames for particular parent

#ParentName > QFrame will select all QFrames that are children of #ParentName

#ParentName QFrame will select all QFrames contained in #ParentName and it's children

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top