Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to Develop a Calendar Widget.
Qt 6.11 is out! See what's new in the release blog

How to Develop a Calendar Widget.

Scheduled Pinned Locked Moved Mobile and Embedded
119 Posts 11 Posters 149.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #82

    [quote author="BorahAnshuman" date="1303188835"]hello friends

    i want to change the font color for dates of calendar according to holidays ...for that i have used Qtextformat...but dont know hw can i use it to change the color of the font[/quote]

    If the background color of a cell is controlled by setBackground, then it did not occor to you to look into the documentation of setForeground?

    [quote]
    Sets the foreground brush to the specified brush. The foreground brush is mostly used to render text.

    See also foreground(), clearForeground(), and setBackground().
    [/quote]

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BorahAnshuman
      wrote on last edited by
      #83

      Thanks for ur reply...its working..

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BorahAnshuman
        wrote on last edited by
        #84

        hello Andre

        sorry for sending the question again...

        how can i set backgroundImageUrl in each cell in calender…Actually i had use QTextCharformat for doing that but it not work..code i hv written is..
        @QTextCharFormat format;

        format.BackgroundImageUrl;@
        My question is how can i set image url here….any clue please suggest..
        thanks

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #85

          I think you will need to use something like this:"

          @
          QUrl imageUrl;
          //set the url to some valid value
          format.setProperty(QTextFormat::BackgroundImageUrl, QVariant(imageUrl));
          @

          But I don't think that will work, because the QCalendarWidget documentation states:
          [quote]
          Only a subset of the properties in QTextCharFormat are used by the calendar widget. Currently, the foreground, background and font properties are used to determine the rendering of individual cells in the widget.[/quote]

          Seems like you can only use the QTextCharFormat for the simple stuff, not for the fancy stuff. If you need to put an image in a cell, you are going to need to subclass QCalendarWidget and reimplement paintCell to do the rendering of your cells yourself.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            BorahAnshuman
            wrote on last edited by
            #86

            hello andre

            i had implement ur code like this..

            @QUrl url = QUrl::fromEncoded("http://baytrail.abag.ca.gov/vtour/map4/access/CyteHils/Trail_to_Red_Hill_Summit.JPG");

            safedate.setProperty(QTextCharFormat::BackgroundImageUrl,QVariant(url));//safedate is an object of QTextCharFormat
            
            ui->calendarWidget->setDateTextFormat(QDate(2011,4,19),startdate);@
            

            but its not working..is anything missing here

            regards
            Anshuman

            1 Reply Last reply
            0
            • I Offline
              I Offline
              imrrk
              wrote on last edited by
              #87

              hello andre,have you observed in the qcalendarwidget,at first time it shows the currentdate,but when we select a different date ,their is no such marker which tells that it is a currentdate,i mean to say that the currentdate should be underlined so that when a user selects a different date ,the currentdate can be identified by the underlined mark.

              Regards
              imrrk

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #88

                [quote author="BorahAnshuman" date="1303196388"]hello andre

                i had implement ur code like this..

                @QUrl url = QUrl::fromEncoded("http://baytrail.abag.ca.gov/vtour/map4/access/CyteHils/Trail_to_Red_Hill_Summit.JPG");

                safedate.setProperty(QTextCharFormat::BackgroundImageUrl,QVariant(url));//safedate is an object of QTextCharFormat
                
                ui->calendarWidget->setDateTextFormat(QDate(2011,4,19),startdate);@
                

                but its not working..is anything missing here

                regards
                Anshuman[/quote]

                What is missing, is that you did not read beyond the code snippet I posted. You know, the part that states that the code snippet is not going to work, as documented for QCalendarWidget, and that you need other ways of doing this.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #89

                  [quote author="imrrk" date="1303196445"]hello andre,have you observed in the qcalendarwidget,at first time it shows the currentdate,but when we select a different date ,their is no such marker which tells that it is a currentdate,i mean to say that the currentdate should be underlined so that when a user selects a different date ,the currentdate can be identified by the underlined mark.

                  Regards
                  imrrk
                  [/quote]
                  So, why don't you set a different QTextCharFormat for the current date then? You can change the font using that class...

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    imrrk
                    wrote on last edited by
                    #90

                    ok thanks andre,i got it

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      BorahAnshuman
                      wrote on last edited by
                      #91

                      Hello andre

                      As i am very new to qt so can u give me a brief idea of hw to implement paintCell to do the rendering of each cell...

                      with regards
                      Anshuman

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #92

                        Why don't you use the QCalendarWidget sources as inspiration for that?

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          BorahAnshuman
                          wrote on last edited by
                          #93

                          hello andre

                          thanks for ur reply..

                          Actually i hv been go through that source code..but i havent found any idea regarding setting of background image in particular cell..and as u said that to set an image in a particular cell we hv to implement paintcell to do the rendering of each cell…but hw this can be done..can u give me an idea for that

                          with regards
                          Anshuman

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            goetz
                            wrote on last edited by
                            #94

                            The signature of the method is:

                            @
                            QCalendarWidget::paintCell(QPainter *painter, const QRect &rect, const QDate &date)
                            @

                            So, I suggest you have a look at QPainter's drawImage(), drawPixmap() and drawPicture() methods.

                            http://www.catb.org/~esr/faqs/smart-questions.html

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              andre
                              wrote on last edited by
                              #95

                              You know what? Perhaps you should look into this yourself. Did you look in the documentation for QPainter?

                              1 Reply Last reply
                              0
                              • I Offline
                                I Offline
                                imrrk
                                wrote on last edited by
                                #96

                                hey volker through paintcell method can we add image to the particular cells in calendarwidget?.in my project i have directly taken the qcalendarwidget and dragged it in the form,so how i should implement it.

                                regards
                                imrrk

                                1 Reply Last reply
                                0
                                • G Offline
                                  G Offline
                                  goetz
                                  wrote on last edited by
                                  #97

                                  [quote author="imrrk" date="1303207582"]hey volker through paintcell method can we add image to the particular cells in calendarwidget..
                                  [/quote]

                                  You know the meaning of the sign "?", don't you? If so, then please use it appropriately, if not, please look up in google.

                                  And now, please read the documentation on QPainter. We will not do this for you, this is your part! It has all the information you need and to start playing around.

                                  http://www.catb.org/~esr/faqs/smart-questions.html

                                  1 Reply Last reply
                                  0
                                  • Z Offline
                                    Z Offline
                                    ZapB
                                    wrote on last edited by
                                    #98

                                    Please just try it. Andre and Volker are not your personal assistants. They have even told you which QPainter calls to read up on. The clue is in the name QPainter::drawPixmap()!

                                    Nokia Certified Qt Specialist
                                    Interested in hearing about Qt related work

                                    1 Reply Last reply
                                    0
                                    • I Offline
                                      I Offline
                                      imrrk
                                      wrote on last edited by
                                      #99

                                      i know volker,fine,i will read the doc and get back to you with my code..

                                      regards
                                      imrrk

                                      1 Reply Last reply
                                      0
                                      • B Offline
                                        B Offline
                                        BorahAnshuman
                                        wrote on last edited by
                                        #100

                                        hello volker

                                        actually i had read about QPainters but doesnt know hw to implement it..from where to start

                                        i had given a code,,u plz check it whether its ok to work or not..

                                        @QPainter* pPainter = new QPainter(this);
                                        pPainter->drawPixmap(rect(), QPixmap(":/images/bg.png"));@

                                        after that what should i do cant find it
                                        regards

                                        Anshuman

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          goetz
                                          wrote on last edited by
                                          #101

                                          Read the docs. If you really do so, you will find a link to an example that even contains drawing pixmaps. Grab it, play with it, adapt it. This all is really basic stuff, explained multiple times in the docs with uncountable examples in the docs. We're not going to do your homework!

                                          http://www.catb.org/~esr/faqs/smart-questions.html

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved