daisy
daisy

Reputation: 23571

Represent drop down menu of QPushButton with Qt Style Sheet?

I'm wondering which is a proper way for representing the menu dropped down from a QPushButton ?

QPushButton::drop-down { blabla }

doesn't work

Upvotes: 2

Views: 2085

Answers (2)

Nicolas Holthaus
Nicolas Holthaus

Reputation: 8293

In QT Style Sheets, you can style widgets that are members of other widgets like so:

QPushButton QMenu
{
    /* blahblah */
}

Where QPushButton is the parent widget, and QMenu is the child. It also works for other stylable items and pseudo-states, for example

QPushButton QMenu::separator
{
    height: 1px;
    border-bottom: 1px solid lightGray;
    background: #5A5A5A;
    margin-left: 2px;
    margin-right: 0px;
    margin-top: 2px;
    margin-bottom: 2px;
 }

Upvotes: 1

Arnold Spence
Arnold Spence

Reputation: 22282

When you set the menu for a QPushButton using setMenu(), the menu continues to exist as its own entity so you would target the QMenu object itself with an appropriate selector. A QMenu supports the box model. Some example styling can be found here.

Upvotes: 0

Related Questions