Results 1 to 16 of 16

Thread: How To Change Style Sheet for QCalendarWidget

  1. #1
    Join Date
    Mar 2010
    Location
    Ahmedabad, Gujarat
    Posts
    35
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How To Change Style Sheet for QCalendarWidget

    Hey ,
    can any body tell me how to change the style sheet for QCalendarWidget?
    mainly i want to change the backgroung-color of navigationbar...!

    Qt Code:
    1. QWidget *widget = new QWidget;
    2.  
    3. QCalendarWidget *calendar = new QCalendarWidget(widget);
    4. QString style="QMenu { font-size:16px; width: 150px; left: 20px;"
    5. "background-color:qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 #cccccc, stop: 1 #333333);}"
    6. "QToolButton {icon-size: 48px, 48px;background-color: qlineargradient(x1:0, y1:0, x2:0,"
    7. "y2:1, stop: 0 #cccccc, stop: 1 #333333);"
    8. "height: 100px; width: 200px;}"
    9. "QAbstractItemView {selection-background-color: rgb(255, 174, 0);}"
    10. "QToolButton::menu-arrow {}"
    11. "QToolButton::menu-button {}"
    12. "QToolButton::menu-indicator{width: 50px;}"
    13. "QToolButton::menu-indicator:pressed,"
    14. "QToolButton::menu-indicator:open{top:10px; left: 10px;}"
    15. "QListView {background-color:white;}"
    16. "QSpinBox::up-button { subcontrol-origin: border;"
    17. "subcontrol-position: top right; width:50px; border-image: url(icons:arrow_up_n.png);}"
    18. "QSpinBox::down-button {subcontrol-origin: border; subcontrol-position: bottom right;"
    19. "border-width: 1px; width:50px;}"
    20. "QSpinBox::down-arrow { width:26px; height:17px;"
    21. "image: url(icons:arrow_down_n.png); } ";
    22.  
    23. calendar->setStyleSheet(style);
    To copy to clipboard, switch view to plain text mode 

    what should I add more to this?

    thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How To Change Style Sheet for QCalendarWidget

    The calender widget can not be customized by stylesheets (yet)

  3. #3
    Join Date
    Mar 2010
    Location
    Ahmedabad, Gujarat
    Posts
    35
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How To Change Style Sheet for QCalendarWidget

    the above stuff works fine ....!!!
    calendarwidget's style sheet is getting changed but can't do for navigation bar...
    plz help...!
    thanks.

  4. #4
    Join Date
    Mar 2010
    Location
    Ahmedabad, Gujarat
    Posts
    35
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How To Change Style Sheet for QCalendarWidget

    can any body help please...?


    i have tried many conbination but can't do it..!

  5. #5
    Join Date
    Mar 2010
    Location
    Ahmedabad, Gujarat
    Posts
    35
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How To Change Style Sheet for QCalendarWidget

    anybody........?

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How To Change Style Sheet for QCalendarWidget

    I don't want to sound like a jackass, but READ THE DOCUMENTATION!!!
    You CAN NOT style the calender widget via style sheets, IT IS DOCUMENTED!

    Sure, you can change the background because after all, the calender widget is based on QWidget.

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Change Style Sheet for QCalendarWidget

    You will need to subclass QCalendarWidget and do the styling yourself for the navigation bar.
    You can look into the source code for QCalendarWidget

  8. The following user says thank you to aamer4yu for this useful post:

    jthacker (8th May 2010)

  9. #8
    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: How To Change Style Sheet for QCalendarWidget

    The navigation bar is made of buttons so in theory styling the buttons inside the widget should be possible. At least simple things (such as changing colours of foreground and background) seem to work. The bar as a whole is probably not stylable, as already written.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    jthacker (8th May 2010)

  11. #9
    Join Date
    Mar 2010
    Location
    Ahmedabad, Gujarat
    Posts
    35
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How To Change Style Sheet for QCalendarWidget

    hey thanx evetybody..!

  12. #10
    Join Date
    May 2010
    Location
    Czestochowa, Poland
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Change Style Sheet for QCalendarWidget

    Actually, it is possible to style the navigation bar. I've done it before, here's code from a real-world application:
    Qt Code:
    1. // Hack: change calendar title colors
    2. QWidget *calendarNavBar = calendar->findChild<QWidget *>("qt_calendar_navigationbar");
    3. if (calendarNavBar) {
    4. QPalette pal = calendarNavBar->palette();
    5. pal.setColor(calendarNavBar->backgroundRole(), QColor(220, 231, 245));
    6. pal.setColor(calendarNavBar->foregroundRole(), QColor(21, 28, 85));
    7. calendarNavBar->setPalette(pal);
    8. }
    To copy to clipboard, switch view to plain text mode 
    Of course this code depends on internal implementation of QCalendarWidget, but there's no official way to do it anyway.
    Q7Goodies - The sweetest way to add Windows 7 features to your Qt application

  13. #11
    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: How To Change Style Sheet for QCalendarWidget

    If the widget is called qt_calendar_navigationbar then you can reference it like so:

    css Code:
    1. #qt_calendar_navigationbar {
    2. //...
    3. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #12
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: How To Change Style Sheet for QCalendarWidget

    This thread is three years old, but as it is apparently the only source you can find about styling the calendar popup, chances are, that somebody will find it useful to know, that even things like the nextMonth and prevMonth-Buttons are perfectly stylable.

    This is e.g. important for Necessitas/Android, where those buttons are way to small to be of any use, at least on a highres Amoled tablet screen.

    Some old source code of the widget tells us, what those elements are named:
    prevMonth->setObjectName(QLatin1String("qt_calendar_prevmont h"));
    nextMonth->setObjectName(QLatin1String("qt_calendar_nextmont h"));
    monthButton->setObjectName(QLatin1String("qt_calendar_monthbut ton"));
    yearButton->setObjectName(QLatin1String("qt_calendar_yearbutt on"));
    yearEdit->setObjectName(QLatin1String("qt_calendar_yearedit "));
    This is what I use for my app:
    ->setStyleSheet( "QDateEdit {"
    "min-height:"+QString::number(this->editHeight)+"px; "
    "max-height:"+QString::number(this->editHeight)+"px; "
    "min-width:"+QString::number(this->editWidth)+"px; "
    "margin: 0px; padding-top: 0x; padding-bottom: 0px; "
    "color: rgb(90,31,0); background-color: rgb(253, 231, 146);"
    "}"
    "QDateEdit::up-button { subcontrol-position: right; height: "+QString::number(this->editHeight)+"px; width: "+QString::number(this->controlWidth)+"px;}"// subcontrol-color: rgb(90,31,0);}"
    "QDateEdit::drop-down { subcontrol-position: right; height: "+QString::number(this->editHeight)+"px; width: "+QString::number(this->controlWidth)+"px;}"// background-color: rgb(253, 231, 146);}"
    "QDateEdit::up-button { width: "+QString::number(this->editHeight)+"px; height: "+QString::number(this->editHeight)+"px; background-color: rgb(253, 231, 146); }"
    "QDateEdit::up-arrow { "
    "border-left: "+arrowSizeString+"px solid none;"
    "border-right: "+arrowSizeString+"px solid none;"
    "border-bottom: "+arrowSizeString+"px solid rgb(90,31,0);"
    "width: 0px; height: 0px; }"
    "QDateEdit::drop-down { width: "+QString::number(this->editHeight)+"px; height: "+QString::number(this->editHeight)+"px; background-color: rgb(253, 231, 146); }"
    "QDateEdit::down-arrow { "
    "border-left: "+arrowSizeString+"px solid none;"
    "border-right: "+arrowSizeString+"px solid none;"
    "border-top: "+arrowSizeString+"px solid rgb(90,31,0);"
    "width: 0px; height: 0px; }"
    "#qt_calendar_prevmonth {width: "+QString::number(this->editHeight)+"px; height: "+QString::number(this->editHeight)+"px; icon-size: "+QString::number(this->editHeight)+"px}"
    "#qt_calendar_nextmonth {width: "+QString::number(this->editHeight)+"px; height: "+QString::number(this->editHeight)+"px; icon-size: "+QString::number(this->editHeight)+"px}"

    "margin-bottom: 0px; border-width: 0px; padding: 0px;"
    "min-height:"+QString::number(this->editHeight)+"px; "
    "border: 0px solid rgb(90,31,0);"
    "color: rgb(90,31,0);"

    );

  15. #13
    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: How To Change Style Sheet for QCalendarWidget

    Quote Originally Posted by sedi View Post
    This is e.g. important for Necessitas/Android, where those buttons are way to small to be of any use, at least on a highres Amoled tablet screen.
    See QApplication::setGlobalStrut()
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. The following user says thank you to wysota for this useful post:

    sedi (31st July 2013)

  17. #14
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: How To Change Style Sheet for QCalendarWidget

    I bow my head in awe. Now that's a cool thing to know... Thank you!

  18. #15
    Join Date
    Mar 2010
    Posts
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How To Change Style Sheet for QCalendarWidget

    Here's a comprehensive syling of the QCalendarWidget with stylesheet:

    Qt Code:
    1. /* navigation bar */
    2. QCalendarWidget QWidget#qt_calendar_navigationbar { background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 #cccccc, stop: 1 #333333); }
    3. height: 60px;
    4. width: 150px;
    5. color: white;
    6. font-size: 24px;
    7. icon-size: 56px, 56px;
    8. background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 #cccccc, stop: 1 #333333);
    9. }
    10. width: 150px;
    11. left: 20px;
    12. color: white;
    13. font-size: 18px;
    14. background-color: rgb(100, 100, 100);
    15. }
    16. width: 150px;
    17. font-size:24px;
    18. color: white;
    19. background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 #cccccc, stop: 1 #333333);
    20. selection-background-color: rgb(136, 136, 136);
    21. selection-color: rgb(255, 255, 255);
    22. }
    23. QCalendarWidget QSpinBox::up-button { subcontrol-origin: border; subcontrol-position: top right; width:65px; }
    24. QCalendarWidget QSpinBox::down-button {subcontrol-origin: border; subcontrol-position: bottom right; width:65px;}
    25. QCalendarWidget QSpinBox::up-arrow { width:56px; height:56px; }
    26. QCalendarWidget QSpinBox::down-arrow { width:56px; height:56px; }
    27.  
    28. /* header row */
    29. QCalendarWidget QWidget { alternate-background-color: rgb(128, 128, 128); }
    30.  
    31. /* normal days */
    32. {
    33. font-size:24px;
    34. color: rgb(180, 180, 180);
    35. background-color: black;
    36. selection-background-color: rgb(64, 64, 64);
    37. selection-color: rgb(0, 255, 0);
    38. }
    39.  
    40. /* days in other months */
    41. QCalendarWidget QAbstractItemView:disabled { color: rgb(64, 64, 64); }
    To copy to clipboard, switch view to plain text mode 


    This is a listing of the underlying object tree in a QCalendarWidget:

    Qt Code:
    1. QCalendarWidget [calendarWidget] 115af0a8
    2. QVBoxLayout [] 115ad7c0
    3. QCalendarModel [] 12d58ef8
    4. QCalendarView [qt_calendar_calendarview] 115ac870
    5. QWidget [qt_scrollarea_viewport] 115af1a8
    6. QWidget [qt_scrollarea_hcontainer] 115ad268
    7. QScrollBar [] 115af1e8
    8. QBoxLayout [] 115ad940
    9. QWidget [qt_scrollarea_vcontainer] 115ad298
    10. QScrollBar [] 115af248
    11. QBoxLayout [] 12d599d0
    12. QStyledItemDelegate [] 12d54a90
    13. QHeaderView [] 12d5c648
    14. QWidget [qt_scrollarea_viewport] 12d5c668
    15. QWidget [qt_scrollarea_hcontainer] 12d5cd98
    16. QScrollBar [] 12d5c6a8
    17. QBoxLayout [] 12d5de80
    18. QWidget [qt_scrollarea_vcontainer] 12d5cdc8
    19. QScrollBar [] 12d5c748
    20. QBoxLayout [] 12d5df58
    21. QItemSelectionModel [] 12d8cb60
    22. QHeaderView [] 12d5c848
    23. QWidget [qt_scrollarea_viewport] 12d8bc78
    24. QWidget [qt_scrollarea_hcontainer] 12d5d1e8
    25. QScrollBar [] 12d8bcd8
    26. QBoxLayout [] 12d8ed50
    27. QWidget [qt_scrollarea_vcontainer] 12d5d218
    28. QScrollBar [] 12d8bd58
    29. QBoxLayout [] 12d8ee28
    30. QItemSelectionModel [] 12d8cb70
    31. QTableCornerButton [] 12d8be58
    32. QItemSelectionModel [] 12d8cbd0
    33. QWidget [qt_calendar_navigationbar] 12d8bf58
    34. QPrevNextCalButton [qt_calendar_prevmonth] 12d8bfb8
    35. QPrevNextCalButton [qt_calendar_nextmonth] 12d8bff8
    36. QToolButton [qt_calendar_monthbutton] 12d8c038
    37. QMenu [] 12d8c198
    38. QAction [] 12d8cbe0
    39. QAction [] 12d8cc10
    40. QAction [] 12d8cc20
    41. QAction [] 12d8cc30
    42. QAction [] 12d8cc40
    43. QAction [] 12d8cc50
    44. QAction [] 12d8cc60
    45. QAction [] 12d8cc70
    46. QAction [] 12d8cc80
    47. QAction [] 12d8cc90
    48. QAction [] 12d8cca0
    49. QAction [] 12d8ccb0
    50. QAction [] 12d8ccc0
    51. QToolButton [qt_calendar_yearbutton] 12d996f0
    52. QSpinBox [qt_calendar_yearedit] 12d99730
    53. QLineEdit [qt_spinbox_lineedit] 12d99770
    54. QWidgetLineControl [] 12d4f0d0
    55. QValidator [qt_spinboxvalidator] 12d8f260
    56. QHBoxLayout [] 12d8f290
    57. QCalendarDelegate [] 12d965c8
    58. QCalendarTextNavigator [] 12daac38
    To copy to clipboard, switch view to plain text mode 

  19. The following 2 users say thank you to blooy for this useful post:

    laszlo.gosztola (25th January 2015), RolandHughes (20th February 2016)

  20. #16
    Join Date
    Nov 2008
    Posts
    183
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How To Change Style Sheet for QCalendarWidget

    Sorry to unearth this old thread but my question is directly based on this.

    First off, many thanks to the poster who put up the massive and good looking stylesheet. I have used it for a base and tweaked it for projects. One thing I have spent several hours trying to figure out is how to change the cell spacing via the stylesheet (or in code). In my current embedded target I want to use a 24 point font for the digits. It "should" fit just fine, but padding/cell spacing around the numbers seems to remain constant which shoves the widget off one edge or the other. (Widget has to fit in 500 px wide display.)

    Has anyone found a way to tunnel in changing the width of the columns or the spacing around the cells?

    Thanks in advance.

Similar Threads

  1. How to change weekends red color in QCalendarWidget?
    By Dimon in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2011, 10:50
  2. Problems with Gradient style used through Style sheet on ARM platform
    By puneet.narsapur in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 25th January 2010, 12:48
  3. How to set Style sheet for QCalendarWidget?
    By nifei in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2009, 22:36
  4. Style Sheet speed
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 24th January 2008, 18:40
  5. How to use style sheet
    By safknw in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2006, 13:05

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.