Results 1 to 19 of 19

Thread: How to create a custom Button?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to create a custom Button?

    Quote Originally Posted by jacek View Post
    IMO it would be better to use QPixmapCache instead of loading those pixmaps every time they are needed.
    That's only an example, I wanted to make it as simple as can be. It would be enough to have two static QPixmap members in the class that would hold those pixmaps, I don't see a benefit from the cache here.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create a custom Button?

    Quote Originally Posted by wysota View Post
    That's only an example, I wanted to make it as simple as can be.
    But still, it's an improper example. You've just made it too simple.

    Quote Originally Posted by wysota View Post
    It would be enough to have two static QPixmap members in the class that would hold those pixmaps, I don't see a benefit from the cache here.
    How do you want to initialize static QPixmaps? QApplication instance must be created first.

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

    Default Re: How to create a custom Button?

    Quote Originally Posted by jacek View Post
    But still, it's an improper example. You've just made it too simple.


    How do you want to initialize static QPixmaps? QApplication instance must be created first.
    Somehow I knew you would ask that question

    Qt Code:
    1. class x{
    2. static QPimxap *p1;
    3. static QPixmap *p2;
    4. public x(){
    5. if(!p1){
    6. p1 = new QPixmap(...);
    7. p2 = new QPixmap(...);
    8. }
    9. }
    10. };
    11.  
    12. QPixmap *x::p1 = 0;
    13. QPixmap *x::p2 = 0;
    To copy to clipboard, switch view to plain text mode 
    Of course this causes a slight memory leak if you don't count instances of your class. An alternative is to have those pixmaps directly in the class as regular members, only that it will have a bigger memory footprint.

    BTW. It's not an improper example - you simply don't like it.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create a custom Button?

    Quote Originally Posted by wysota View Post
    It's not an improper example - you simply don't like it.
    It's just unnecessarily inefficient.

  5. #5
    Join Date
    Feb 2006
    Location
    Boulder, Colorado, USA
    Posts
    63
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create a custom Button?

    I've been playing around with the new stylesheet thing and it makes everything much simpler. (The below is a stylesheet, not c++)
    Qt Code:
    1. QCheckBox::indicator:unchecked {
    2. image: url(:/images/checkbox_unchecked.png);
    3. }
    4.  
    5. QCheckBox::indicator:checked {
    6. image: url(:/images/checkbox_checked.png);
    7. }
    To copy to clipboard, switch view to plain text mode 

    This is implemented with qApp->setStyleSheet() globally or with myCheckbox->setStyleSheet() for a particular checkbox. Also, check out the Style Sheet Example

Similar Threads

  1. Create a new button
    By avis_phoenix in forum Qt Programming
    Replies: 7
    Last Post: 3rd September 2006, 18:56
  2. How to create an Insert/Submit button for a form.
    By fnmblot in forum Qt Programming
    Replies: 5
    Last Post: 4th August 2006, 16:18
  3. Example HowTo create custom view
    By dexjam in forum Newbie
    Replies: 6
    Last Post: 12th July 2006, 11:06
  4. custom maximize button---
    By Naveen in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 13:11
  5. How to create custom slot in Qt Designer 4.1?
    By jamadagni in forum Qt Tools
    Replies: 31
    Last Post: 18th January 2006, 20:46

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
  •  
Qt is a trademark of The Qt Company.