Results 1 to 8 of 8

Thread: Custom buttons problem

  1. #1
    Join Date
    Dec 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Custom buttons problem

    Hi,

    I'd like to create custom buttons.
    for example: I've got 2 buttons and I want them different.

    How can I do this?

    I read the Qt Style Sheets Examples, and there is an example
    QPushButton#evilButton { background-color: red }

    I guess the evilButton is the name of the QPushButton, but if I create a QPushButton:

    for example: QPushButton *hidePreferences;
    I can't customize it with the QPushButton#hidePreferences reference.

    How can I do this?

    giotto

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Custom buttons problem

    From Selector Types:
    ID Selector QPushButton#okButton Matches all QPushButton instances whose object name is okButton.
    Qt Code:
    1. hidePreferences->setObjectName("hidePreferences");
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    giotto (7th February 2008)

  4. #3
    Join Date
    Dec 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Thumbs up Re: Custom buttons problem

    Quote Originally Posted by jpn View Post
    From Selector Types:


    Qt Code:
    1. hidePreferences->setObjectName("hidePreferences");
    To copy to clipboard, switch view to plain text mode 
    Thanks it works, but only for one object.

    If I set up two objectes, with different names, only the firsts' style is changed. If I flips the styles in the stylesheet file than the second is styled
    Last edited by giotto; 7th February 2008 at 16:18.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom buttons problem

    Maybe you should answer this question first - what exactly are you trying to obtain? Please provide a little more descriptive explanation.

  6. #5
    Join Date
    Dec 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Custom buttons problem

    Quote Originally Posted by wysota View Post
    Maybe you should answer this question first - what exactly are you trying to obtain? Please provide a little more descriptive explanation.
    Well,

    I'd like to create ten radiobuttons. These buttons change color of the widget. And I like to set an image for each button. for example: the yellow radiobutton will have a yellow image, the green will have a green image to show the exactly color, which will be set.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom buttons problem

    It'll be best if you use Designer to layout your buttons. You can then right click each button and choose the option to modify the stylesheet of each button. If you don't want to use Designer, you don't have to - you can use QWidget::setStyleSheet() to style each widget separately.

    Qt Code:
    1. greenButton->setStyleSheet("background-color: green;");
    2. redButton->setStyleSheet("background-color: red;");
    3. blueButton->setStyleSheet("background-color: blue;");
    To copy to clipboard, switch view to plain text mode 

  8. #7
    Join Date
    Dec 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Custom buttons problem

    Actually, this is how it is working now, but I don't want to burn it into the source. I want to separate the stylesheets, into a qss file, but I don't know how to access it. Somehow I can reach only the first reference....

  9. #8
    Join Date
    Dec 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Custom buttons problem

    Damn!

    There was a syntax error in the qss file, now everything works fine....

Similar Threads

  1. Problem with custom container widget
    By MrGarbage in forum Qt Tools
    Replies: 4
    Last Post: 25th August 2007, 03:37
  2. Problem with Parent QWidget and Buttons not working
    By VireX in forum Qt Programming
    Replies: 7
    Last Post: 11th May 2007, 22:24
  3. Problem applying setWindowOpacity to a custom Widget
    By yellowmat in forum Qt Programming
    Replies: 8
    Last Post: 1st November 2006, 10:05
  4. Problem reimplementing QSpinBox in a custom widget
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2006, 08:12
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.