문제
QT Symbian 프로젝트를 구축하고 있으며 몇 초 후에 자동 닫아야하는 사용자에게 알림을 표시하고 싶습니다. 나는 Nokia가 UI에서 이것을 많이 사용하는 것을 보았습니다.
지금은 아래 코드를 사용하여 사용자가 QMessageBox를 닫을 수 있지만 1 ~ 2 초 후에 QMessageBox를 자동으로 닫을 수있는 경우 원합니다. QT를 사용하여 어떻게해야합니까?
QMessageBox msgBox;
msgBox.setText("Hello!");
msgBox.setIcon(QMessageBox::Information);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
해결책
나는 서브 클래스를 제안합니다 QMessageBox
원하는 행동을 추가하려면 ...
같은 방법을 추가하는 것이 흥미로울 것입니다 setAutoClose(bool)
그리고 setAutoCloseTimeout(int)
그리고 트리거 a QTimer
~에 showEvent
Autoclose 옵션이 활성화 된 경우!
이런 식으로, 당신은 당신의 QMessageBox
그리고 "이 상자가 xxx 초 안에 자동으로 닫히게됩니다 ..."또는 진행 막대 등이라는 텍스트가 있습니다 ...
다른 팁
정말 감사합니다! 내 해결책 :
나는 내 자신의 수업을 만들었습니다 (MessageBox) 이것은 그것을 보여주는 내 코드입니다.
MessageBox msgBox;
msgBox.setText("Hello!");
msgBox.setIcon(QMessageBox::Information);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setAutoClose(true);
msgBox.setTimeout(3); //Closes after three seconds
msgBox.exec();
이것은 내 수업입니다 :
class MessageBox : public QMessageBox
int timeout;
bool autoClose;
int currentTime;
void MessageBox::showEvent ( QShowEvent * event ) {
currentTime = 0;
if (autoClose) {
this->startTimer(1000);
}
}
void MessageBox::timerEvent(QTimerEvent *event)
{
currentTime++;
if (currentTime>=timeout) {
this->done(0);
}
}
대신 사용할 수 있습니다 Singleshot
대화 상자를 닫는 타이머 또는 QLabel
훨씬 쉽게 :
QTimer *timer;
QTimer::singleShot(10000, msgBox, SLOT(close()));
이 코드로 :
QTimer *timer;
QTimer::singleShot(10000, msgBox, SLOT(close()));
당신은 얻는다 :
QObject::connect: Incompatible sender/receiver arguments
QTimer::timeout() --> QMessageBox::
Msgbox (수신기)는 QTCore 객체 여야합니다. 및 QMESSAGEBOX 서브 클래스 QTGUI 여야합니다. 보다 https://srinikom.github.io/pyside-docs/pyside/qtcore/qtimer.html#pyside.qtcore.pyside.qtcore.qtimer.singleshot
이것은 누군가를 도울 수 있습니다.
msgBox.button(QMessageBox::Ok)->animateClick(5000);
메시지 상자는 5 초 후에 닫힙니다.