×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Angry Style sheets are driving me crazy

    (As if I wasn't there already)

    When I set a style sheet with a background-image in the centralWidget, it's getting picked up by other widgets attached to the centralWidget and the background image, rather than simply "showing through", starts anew in each widget. Eg, the background-image has rounded corners, and the several widgets that are picking up the style sheet now have rounded top left corners.

    How do I eliminate this behavior? I've tried various incantations such as setStyleSheet(QString()) and background-image:none, but nothing seems to have any effect on this.

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Style sheets are driving me crazy

    Please, attach sample. It should be trivial according to the description.

  3. #3
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Style sheets are driving me crazy

    Code:
       void retranslateUi(QMainWindow *MainWindow)
        {
            MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
            centralWidget->setStyleSheet(QApplication::translate("MainWindow", "background-image: url(:/images/FullLightBackground_CenterBar.png);\n"
    "background-repeat:repeat-no;", 0, QApplication::UnicodeUTF8));
        } // retranslateUi
    I don't know how to "attach" an image.

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Style sheets are driving me crazy

    Here's the image:



    Setting the background (and, I suspect, any use of the stylesheet) also has the untoward effect of clobbering the font set for the contained widget.

  5. #5
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Style sheets are driving me crazy

    Why do you translate style rule?
    retranslateUi is a strange place for setting a style. It's better to do in MainWindow constructor or even main function.
    Proper rule would be something like that:
    Code:
    centralWidget->setStyleSheet("MainWindow { background-image: url(:/images/FullLightBackground_CenterBar.png);"
                                 "background-repeat:repeat-no; }");
    Last edited by divanov; 2010-01-23 at 00:19.

  6. #6
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Style sheets are driving me crazy

    Why do you translate style rule?
    retranslateUi is a strange place for setting a style. It's better to do in MainWindow constructor or even main function.
    That's where Designer puts it. I've tried it the other way too. It's all effectively the same.

  7. #7
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Style sheets are driving me crazy

    Code:
    #include <QApplication>
    #include <QMainWindow>
    #include <QPushButton>
    #include <QGridLayout>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        a.setStyleSheet("QWidget#CentralWidget {border-image: url(:test.png) 0 0 0 0");
    
        QMainWindow window;
        QWidget widget;
        QPushButton button1("Button 1");
        QPushButton button2("Button 2");
        QPushButton button3("Button 3");
        QPushButton button4("Button 4");
        QGridLayout grid;
     
        grid.addWidget(&button1, 0, 0);
        grid.addWidget(&button2, 0, 1);
        grid.addWidget(&button3, 1, 0, 1, 2);
        grid.addWidget(&button4, 2, 0, 1, 2);
    
        widget.setObjectName("CentralWidget");
        widget.setLayout(&grid);
    
        window.setCentralWidget(&widget);
        window.show();
    
        return a.exec();
    }
    Last edited by divanov; 2010-01-23 at 07:35.

  8. #8
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Style sheets are driving me crazy

    Yeah, I figured out (with your help) that the style info must be "targeted" to the specific widget. Designer gives the impression that it's letting you set specific styles with each widget, but such is not the case.

    Still don't have a good explanation of why having any style at all seems to clobber font info set via QWidget::setFont, but I can live with the way it works.

Similar Threads

  1. Replies: 5
    Last Post: 2009-08-19, 08:31
  2. n96 is driving me crazy, please help.......
    By nikkoSH in forum Mobile Java General
    Replies: 17
    Last Post: 2009-03-27, 17:13
  3. dynamic style
    By jamapag in forum Widsets Development
    Replies: 1
    Last Post: 2009-01-08, 22:36
  4. Rogue key event trap driving me crazy
    By slitchfield in forum Symbian
    Replies: 1
    Last Post: 2007-08-12, 16:40
  5. self.img.text - how to set text style
    By novis in forum Symbian
    Replies: 4
    Last Post: 2007-07-12, 15:52

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×