Could a cardinal or pope have children if they are a widower? Could it be possible for a cardinal,or even the pope to have children,if he had been married previously,and then taken up holy orders after being widowed?

This would seem to fulfil the requirements of not being married and also being celibate whilst being a priest,but I can't find a definitive answer-all the celibacy guidelines seem to just refer to during the period of the priesthood.
Yes, a pope or cardinal could have children if his wife died before he was ordained a deacon and then priest. This would fulfill the requirements for ordination to the priesthood. It could also conceivably happen that a permanent deacon could go on to become a priest and then bishop, cardinal and finally pope after the death of his wife. I know personally a priest in the Diocese of Tulsa who was a permanent deacon that became a priest after the death of his spouse. 

Not totally the best example, but an example nonetheless is the fact that Bishop Jean-François de Hercé (1838-1848) of the Diocese of Nantes was ordained a priest after the death of his wife on December 18,1830 and was consecrated a bishop on April 17, 1836. 

After the death of his wife in 1820 and the marriage of his daughter Marie-Lucie with Guillaume-François d'Ozouville in 1825, Jean-François entered the seminary at the age of 54. 

As a bishop of the Catholic Church, it would be conceivable (but did not happen) for Bishop Jean-François de Hercé to named a cardinal by the pope and then elected to become the pope in a conclave.

His French biography Père, Maire, Evêque (Father, Mayor, Bishop) is an excellent read.

As we know the Apostle St. Peter became the first pope and that he was married. There are some traditions and legends that he may have had children. The Roman Martyrology seems to acknowledge Saint Peter's paternity:  


  "St. Petronilla, Virgin [and Martyr], daughter of the blessed apostle Peter, who refused to marry the nobleman Flaccus. Given three days for consideration, she spent them in fasting and prayer. On the third day, having received Christ sacramentally, she gave up her spirit." Roman Martyrology (May 31).