Results 1 to 6 of 6

Thread: QCalendar Widget styling

  1. #1
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QCalendar Widget styling

    Hi,

    I am looking to create a simple organizer using Qt. I realize that one way of doing it is by subclassing QCalendarWidget and overriding the paintCell method. But it seems that css cannot be used to style qcalendarwiget and only the background image can be changed.

    I do not have the time to implement the entire calendar by myself, is there any way to style the calendar using CSS ?

    Thanks

  2. #2
    Join Date
    Nov 2008
    Location
    Częstochowa/Poland
    Posts
    50
    Thanks
    2
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCalendar Widget styling

    It's very easy to implement a calendar using QDate and QGraphicsView.
    Screen

  3. #3
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QCalendar Widget styling

    Hi,
    I was able to change my calendar widget using CSS, qtopia support told me that CSS is not fully implemented yet for the calendar widget. I used QToolButton, QMenu, QListview, and was able to change the arrows, background, month popup menu. I looked at the actual code in the qcalendarwidget.cpp file to see what widgets it used and then put my stylesheet onto those widgets.
    If you need my code let me know.

  4. #4
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QCalendar Widget styling

    As requested here is my stylesheet. It was customized for color and icons, mainly I needed larger selectors (arrows, and tool menu) since I am using a touchscreen and not a mouse. When I touch the month, the pop menu appears.
    I had a difficult time getting the next/previous months icons working so qt supported suggested this.
    Qt Code:
    1. QToolButton *btn = calendar->findChild<QToolButton *>("qt_calendar_prevmonth");
    2. QIcon icon;
    3. icon.addPixmap(QPixmap(QString::fromUtf8(PREVMONTHBUTTON_N)), QIcon::Normal, QIcon::On);
    4. icon.addPixmap(QPixmap(QString::fromUtf8(PREVMONTHBUTTON_S)), QIcon::Active, QIcon::On);
    5. icon.addPixmap(QPixmap(QString::fromUtf8(PREVMONTHBUTTON_S)), QIcon::Selected, QIcon::On);
    6. btn->setIcon(icon);
    7. btn = calendar->findChild<QToolButton *>("qt_calendar_nextmonth");
    8. ....
    To copy to clipboard, switch view to plain text mode 
    StyleSheet, there are some style widgets that are blank, just ignore them.
    Qt Code:
    1. calendar->setStyleSheet("QMenu { font-size:16px; width: 150px; left: 20px; background-
    2. color:qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 #cccccc, stop: 1 #333333);}
    3. QToolButton {icon-size: 48px, 48px;background-color: qlineargradient(x1:0, y1:0, x2:0,
    4. y2:1, stop: 0 #cccccc, stop: 1 #333333);
    5. height: 100px; width: 200px;}
    6. QAbstractItemView {selection-background-color: rgb(255, 174, 0);}
    7. QToolButton::menu-arrow {}
    8. QToolButton::menu-button {}
    9. QToolButton::menu-indicator{width: 50px;}
    10. QToolButton::menu-indicator:pressed,
    11. QToolButton::menu-indicator:open{top:10px; left: 10px;}
    12. QListView {background-color:white;}
    13. QSpinBox {width:200px; border-width: 2px;}
    14. QSpinBox::up-button { subcontrol-origin: border;
    15. subcontrol-position: top right; width:50px; border-image: url(icons:arrow_up_n.png);}
    16. QSpinBox::down-button {subcontrol-origin: border; subcontrol-position: bottom right;
    17. border-width: 1px; width:50px;}
    18. QSpinBox::down-arrow { width:26px; height:17px;
    19. image: url(icons:arrow_down_n.png); } ")
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  5. The following 4 users say thank you to QbelcorT for this useful post:

    Alex Snet (16th April 2009), Serenity (10th December 2010), succorguy (18th April 2009), Tomasz (7th December 2010)

  6. #5
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCalendar Widget styling

    Hi QbelcorT,

    Thanks for the code snippets . Since I'm beginning to learn Qt, it would be great if I could have the entire source code with all icons . This should help me greatly in understanding the basics of Qt.

    Thanks a lot.

  7. #6
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QCalendar Widget styling

    Can I change the color of numbers of a week, and names of days? Actually I mean background color. Because I'm trying with no result.

    ----------------------------------------
    SOLVED.

    I've changed QAbstractItemView stylesheet.

    thanks in advance
    best regards
    Tomasz
    Last edited by Tomasz; 7th December 2010 at 23:25.

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Widget Focus
    By navi1084 in forum Qt Programming
    Replies: 6
    Last Post: 29th September 2008, 10:22
  3. Playbutton functionality
    By uchennaanyanwu in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2008, 22:29
  4. How to Open & Close a Widget ?!!
    By Fatla in forum Qt Programming
    Replies: 6
    Last Post: 13th June 2008, 20:39
  5. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35

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.