Results 1 to 8 of 8

Thread: Texturizing Widgets

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Texturizing Widgets

    I am trying to customize the look of my application; reading the documentation I have found this example, in which is shown how apply texture to pushbutton; what I need is apply texture to a QListView background (instead of a flat color) and to scrollbars: which primitive element should I use? Is it possible, in a qlistview, apply different textures for the normal state and the selected one?

    Regards
    Giuseppe CalÃ

  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: Texturizing Widgets

    I'd rather use style sheets nowadays..
    J-P Nurmi

  3. #3
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Texturizing Widgets

    Why? It seems simpler than the drawPrimitive() approach.

    Thanks
    Giuseppe CalÃ

  4. #4
    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: Texturizing Widgets

    J-P Nurmi

  5. #5
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Texturizing Widgets

    Well, you are right. Writing:

    Qt Code:
    1. listView->setStyleSheet("background-image: url(:images/notselected.png)");
    To copy to clipboard, switch view to plain text mode 

    is very quick.

    How about the selected state for a qlistview item? Reading through properties I have found selection-background-color; how can i apply a texture also to the selected state?

    Thanks
    Giuseppe CalÃ

  6. #6
    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: Texturizing Widgets

    Notice that selection-background-color takes a Brush. Furthermore, Brush can be a PaletteRole. So you could combine QPalette and style sheets to achieve that:
    Qt Code:
    1. QPalette palette = listView->palette();
    2. palette.setBrush(QPalette::Highlight, QBrush(QPixmap("selection-background.png")));
    3. listView->setPalette(palette);
    4. listView->setStyleSheet("selection-color: palette(highlight)");
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    jiveaxe (9th November 2007)

  8. #7
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Texturizing Widgets

    I am worked on jpn's last code and this is the final implementation:

    Qt Code:
    1. GmcListView::GmcListView(QWidget *parent)
    2. :QListView(parent)
    3. {
    4. setEditTriggers(QAbstractItemView::NoEditTriggers );
    5. QPalette palette = this->palette();
    6. palette.setBrush(QPalette::Highlight, QBrush(QPixmap(":images/selected.png")));
    7. palette.setBrush(QPalette::Base, QBrush(QPixmap(":images/notselected.png")));
    8. setPalette(palette);
    9. }
    To copy to clipboard, switch view to plain text mode 

    (no need to use setStyleSheet()).

    Now I have customize the scrollbar look. I'd thought to create a QScrollBar widget with listView as parent thinking so to substitute the default one and working on it, but now my listView have two scrollbars...

    Soon as I have a solution will post it.
    Giuseppe CalÃ

  9. #8
    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: Texturizing Widgets

    Quote Originally Posted by jiveaxe View Post
    Now I have customize the scrollbar look. I'd thought to create a QScrollBar widget with listView as parent thinking so to substitute the default one and working on it, but now my listView have two scrollbars...
    There is no need to create new scroll bars. You can access the existing scrollbars via QAbstractScrollArea::horizontalScrollBar() and QAbstractScrollArea::verticalScrollBar(). Notice that there are quite a few "Customizing QScrollBar" examples: http://doc.trolltech.com/4.3/stylesh...ing-qscrollbar

    Also, you can simply use style sheet selectors to apply the stylesheet to a certain scrollbar. For example a QScrollBar which is child of a QListView:
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. Qt3 - Multiple transparent widgets
    By bythesea in forum Qt Programming
    Replies: 4
    Last Post: 11th September 2009, 11:24
  2. widgets behind hidden widgets not working
    By bpetty in forum Newbie
    Replies: 13
    Last Post: 7th September 2007, 20:23
  3. Performance in hiding/showing widgets
    By Paalrammer in forum Newbie
    Replies: 12
    Last Post: 14th February 2007, 18:57
  4. Replies: 11
    Last Post: 7th July 2006, 13:09
  5. Creating Widgets
    By hylke in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2006, 08:37

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.