Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, January 2008
Parent Styles


Message 1 in thread

Hi all,

I want to create a custom widget that needs to be
dropped on a window. The parent window has loaded some
generic styles. I would like that my custom widget not
to inherit any styles from its parent, and be
displayed with the base style. Is this possible ?

Thanks and Happy New Year,
Danny


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


Message 2 in thread

Danny Sporea wrote:
> Hi all,
> 
> I want to create a custom widget that needs to be
> dropped on a window. The parent window has loaded some
> generic styles. I would like that my custom widget not
> to inherit any styles from its parent, and be
> displayed with the base style. Is this possible ?
> 
> Thanks and Happy New Year,
> Danny

Hi Danny,

When you say base style, you mean the application's style? You can 
explicitly override the parent's style for your widget by doing:

myWidget.setStyle(QApplication.style());

-

Gunnar


Message 3 in thread

This doesn't seem to work.

Here is what I have: a QDialog myForm which contains
myWidget. When creating myForm, I'm applying a
stylesheet using myForm.setStyleSheet(...). Myform is
a generic window that is used all over the application
and the styles applied to it customize the look and
feel for the whole application. However, myWidget,
looks bad when the styles are applied to myForm. I
need myWidget (and all its components) to have the
default style and not inherit anything from myForm...

Thanks,
Danny


--- Gunnar Sletta <gunnar@xxxxxxxxxxxxx> wrote:

> Danny Sporea wrote:
> > Hi all,
> > 
> > I want to create a custom widget that needs to be
> > dropped on a window. The parent window has loaded
> some
> > generic styles. I would like that my custom widget
> not
> > to inherit any styles from its parent, and be
> > displayed with the base style. Is this possible ?
> > 
> > Thanks and Happy New Year,
> > Danny
> 
> Hi Danny,
> 
> When you say base style, you mean the application's
> style? You can 
> explicitly override the parent's style for your
> widget by doing:
> 
> myWidget.setStyle(QApplication.style());
> 
> -
> 
> Gunnar
> 



      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs


Message 4 in thread

Danny Sporea wrote:
> This doesn't seem to work.
 >
> Here is what I have: a QDialog myForm which contains
> myWidget. When creating myForm, I'm applying a
> stylesheet using myForm.setStyleSheet(...). Myform is
> a generic window that is used all over the application
> and the styles applied to it customize the look and
> feel for the whole application. However, myWidget,
> looks bad when the styles are applied to myForm. I
> need myWidget (and all its components) to have the
> default style and not inherit anything from myForm...
> 
> Thanks,
> Danny
> 

Hi Danny,

Since you only mentioned styles, I assumed you were talking about 
QStyle. StyleSheets act slightly different...

When you set a stylesheet on a widget it will apply to all its children. 
You can however specify in the stylesheet, which sections apply to what 
kind of widgets. This is documented here:

http://doc.trolltech.com/qtjambi-4.3.3_01/com/trolltech/qt/stylesheet-syntax.html#selector-types

If you want to apply a certain style sheet only to a given class then 
you ideally use the:

MyClass {
     border-style: ...
}

Approach, which selects based on the classname. This will unfortunatly 
not work until Qt Jambi 4.4. The alternative is to make use of the 
object name for instance, as I've done in my example above. You can also 
use a selector to trigger all subclasses classes of QDialog or all 
QDialogs which are in a hierarchy under QMainWindow etc...

I've attached a small example that illustrates how to make the dialog 
use a stylesheet and the sub-widgets behave as default.

best regards,
Gunnar




import com.trolltech.qt.gui.*;
import com.trolltech.qt.gui.*;

public class Test
{
    public static void main(String args[]) {
        QApplication.initialize(args);

        QDialog dialog = new QDialog();
        dialog.setObjectName("TheSpecialDialog");

        QLabel label = new QLabel("Zooty");
        QLineEdit edit = new QLineEdit();
        QPushButton button = new QPushButton("Zoot-Zoot!");


        QHBoxLayout layout = new QHBoxLayout(dialog);
        layout.addWidget(label);
        layout.addWidget(edit);
        layout.addWidget(button);

        dialog.show();

        dialog.setStyleSheet("#TheSpecialDialog {"
                             + "\nbackground-color: blue;"
                             + "\nborder-radius: 5;"
                             + "\nborder-style: solid;"
                             + "\nborder-width: 2;"
                             + "\nborder-color: red;"
                             + "\n}"
                             );


        QApplication.exec();
    }
}