PDA

View Full Version : Do Qt Style Sheets support List-style-image?



daiheitan
11th March 2010, 12:05
I want to customize the image of a QToolButton By Using a QSS(Qt Style sheet) file.
However,the button's normal , hovered , clicked image are just in one PNG file.
I wonder if Qt style sheet support list-style image property,or is there any way to handle this problem?
Or i could only use seperate PNG files?
:confused:
Thanks to Any reply.

moh.gup@gmail.com
11th March 2010, 12:44
You can customize QToolButton .QT documentation describe it in details

Check this If this is helpful to you

Customizing QToolButton

There are three types of QToolButtons.
he QToolButton has no menu. In this case, the QToolButton is styled exactly like QPushButton. See Customizing QPushButton for an example.
The QToolButton has a menu and has the QToolButton::popupMode set to QToolButton::DelayedPopup or QToolButton::InstantPopup. In this case, the QToolButton is styled exactly like a QPushButton with a menu. See Customizing QPushButton for an example of the usage of the menu-indicator pseudo state.
The QToolButton has its QToolButton::popupMode set to QToolButton::MenuButtonPopup. In this case, we style it as follows:


ToolButton { /* all types of tool button */
border: 2px solid #8f8f91;
border-radius: 6px;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f6f7fa, stop: 1 #dadbde);
}

QToolButton[popupMode="1"] { /* only for MenuButtonPopup */
padding-right: 20px; /* make way for the popup button */
}

QToolButton:pressed {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #dadbde, stop: 1 #f6f7fa);
}

/* the subcontrols below are used only in the MenuButtonPopup mode */
QToolButton::menu-button {
border: 2px solid gray;
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
/* 16px width + 4px for border = 20px allocated above */
width: 16px;
}

QToolButton::menu-arrow {
image: url(downarrow.png);
}

QToolButton::menu-arrow:open {
top: 1px; left: 1px; /* shift it a bit */
}

zgulser
11th March 2010, 12:57
Just use seperate png files:)

daiheitan
11th March 2010, 14:10
Wow, display many icons in one PNG file seems to save more space.
If there's no solution,I will just use seperate PNG files.
Hope Qt could add this in a future version.

zgulser
11th March 2010, 14:14
Yeah but how do you think that you access the desired icon from one png?

daiheitan
12th March 2010, 00:58
In CSS there is a way to define width & height of each icon in a PNG file.Anyway...
Another problem is that yesterday Qt Labs announced a technical preview of Qt 4.7& Qt creator 2.0 alpha.I downloaded creator 2.0 alpha,installed while I have already installed Qt 4.6.2.
When compiling(release) a project I found that all image using './resources/...' file url doesn't work.The images just disappeared.But that not appear in creator 1.3.1

-----------------update------------------
well , at first the 'resources' DIR was in 'release' folder.When I copy this folder to the project folder, all things returned to be all right.Maybe there's a change in Qt's file system? Strange.

daiheitan
12th March 2010, 01:41
Oh I made a stupid mistake.
Just ignore my last post...