#include <QtGui>
int main(int argc, char* argv[])
{
toolButton->setText("QToolButton");
layout->addWidget(toolButton);
layout->addWidget(pushButton);
window.show();
toolAction->setDefaultWidget(toolCalendar);
toolMenu->addAction(toolAction);
toolButton->setMenu(toolMenu);
pushAction->setDefaultWidget(pushCalendar);
pushMenu->addAction(pushAction);
pushButton->setMenu(pushMenu);
QObject::connect(toolCalendar,
SIGNAL(currentPageChanged
(int,
int)), pushCalendar,
SLOT(setCurrentPage
(int,
int)));
QObject::connect(pushCalendar,
SIGNAL(currentPageChanged
(int,
int)), toolCalendar,
SLOT(setCurrentPage
(int,
int)));
QObject::connect(toolCalendar,
SIGNAL(clicked
(QDate)), pushCalendar,
SLOT(setSelectedDate
(QDate)));
QObject::connect(pushCalendar,
SIGNAL(clicked
(QDate)), toolCalendar,
SLOT(setSelectedDate
(QDate)));
return app.exec();
}
#include <QtGui>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QWidget window;
QToolButton* toolButton = new QToolButton(&window);
toolButton->setText("QToolButton");
QPushButton* pushButton = new QPushButton("QPushButton", &window);
QHBoxLayout* layout = new QHBoxLayout(&window);
layout->addWidget(toolButton);
layout->addWidget(pushButton);
window.show();
QMenu* toolMenu = new QMenu(toolButton);
QCalendarWidget* toolCalendar = new QCalendarWidget(toolMenu);
QWidgetAction* toolAction = new QWidgetAction(toolMenu);
toolAction->setDefaultWidget(toolCalendar);
toolMenu->addAction(toolAction);
toolButton->setMenu(toolMenu);
QMenu* pushMenu = new QMenu(pushButton);
QCalendarWidget* pushCalendar = new QCalendarWidget(pushMenu);
QWidgetAction* pushAction = new QWidgetAction(pushMenu);
pushAction->setDefaultWidget(pushCalendar);
pushMenu->addAction(pushAction);
pushButton->setMenu(pushMenu);
QObject::connect(toolCalendar, SIGNAL(currentPageChanged(int, int)), pushCalendar, SLOT(setCurrentPage(int, int)));
QObject::connect(pushCalendar, SIGNAL(currentPageChanged(int, int)), toolCalendar, SLOT(setCurrentPage(int, int)));
QObject::connect(toolCalendar, SIGNAL(clicked(QDate)), pushCalendar, SLOT(setSelectedDate(QDate)));
QObject::connect(pushCalendar, SIGNAL(clicked(QDate)), toolCalendar, SLOT(setSelectedDate(QDate)));
return app.exec();
}
To copy to clipboard, switch view to plain text mode
QToolButton is a bit more flexible because it offers different popup modes. The default popup mode is delayed.
Bookmarks