Stopping Border-Image from Giving the Childrens the Same Image



  • Hi everyone,

    I've been exploring with graphics a lot lately. I do my work in Illustrator and import the sliced items to Qt. Unfortunately and this is probably one of the biggest headaches, is the simple fact that all of the MainWindow's childrens inherit that image. I read posts online to get around that problem in code. I can even modify it with just simple CSS within Qt Designer, however, when I do it in Qt Designer with CSS, the image is no longer visible--until I decide to run it. Same with just code, obviously. Here is an example of what I would do with CSS in the designer:

    QMainWindow{
    border-image: url(:/Users/BernW/Desktop/GUI App/images/MainWIndow.png);
    }

    and this will get rid of that problem, however, now Qt Designer is not displaying the image because the QMainWindow{} seems foreign to it.

    I have another way of being able to get my work done, but it is not very clean. Any recommendations? Thanks



  • Okay,

    I figured this could be helpful. Instead of applying an image to the QMainWindow, apply it to the centralWidget and since everything else is pretty much a sibling of centralWidget widget, you will no longer have this problem.

    Now that the statusBar, the mainToolBar, and etc are not inheriting those unwanted features anymore, now it is time to focus on the children of centralWidget. Once you start adding buttons, and other applicable widgets, they are going to inherit, again, an unwanted feature. So, you need to do this:

    QWidget#centralWidget{
    //Your special instructions go here
    }

    and now, with the applicable widgets that you added, they will no longer receive that unwanted feature. In this case, the same background image. To add that CSS, you need to right click on the centralWidget, you can find in the tree on the right, and pick Change styleSheet.

    Just in case, the naming is different, you need to ensure this:

    CLASSNAME #OBJECTNAME{}

    Just look at the tree of all the items for your application you're creating to get the correct name, I don't see a reason though why that name would change, unless Qt created a newer version and just wanted to change the name.

    Now, enjoy Qt!
    Thanks everyone.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.