How do I set a style sheet for one of the widgets in the application? A small detail, to set its objectname.

Source: Internet
Author: User
Tags qt designer

This is a netizen and I talked about the problem, research, is a relatively basic problem, but in the case of handwritten code is easy to ignore.

Q: How do I set a style sheet for a widget in my application that has no effect? This is the method that comes with the QT Help document that applies stylesheet to specific objects, but it doesn't seem to work.

     ID Selector
Qpushbutton#okbutton

A: I really did not pay attention to this, a careful try. Find out the answer is included in the instructions you provided. That is, if you want to set the stylesheet of an object in this window individually, be sure to set its ObjectName property. Of course this refers to the case of writing in code, if you use QT Designer, then there is usually a default objectname, it will work. However, it is often difficult to achieve the ideal stylesheet using QT Designer.

Specific examples are as follows:

     Qdialog Mydialog;
Mydialog.setobjectname ("Mydialog"); If you want to set stylesheet for this object individually, make sure that it's objectname

And then you can write it like this:

Qdialog#mydialog {background-image:url (2.bmp);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.