×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    16

    Question QMessageBox without buttons.

    I want to display a MessageBox / Dialog with text "Hello World" for 2 seconds and then the message box must exit automatically without any user interaction.

    I tried with the following code but is not working. I still get an OK button which i have to press inorder to close the messagebox.

    QString lString("HelloWorld");
    QMessageBox lMessage(QMessageBox::Information, QString("HelloWorld"), (lString), MessageBox::NoButton, this);
    lMessage.setStyleSheet("background: gray");
    lMessage.exec();

    Thanks in advance for the answer.

  2. #2
    Registered User
    Join Date
    Apr 2009
    Posts
    32

    Re: QMessageBox without buttons.

    If I remember correctly on Desktop QMessagebox without a Button is a QDialog and this should be the same on other platforms.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    1

    Re: QMessageBox without buttons.

    Why don't you try startTimer(2000) // for 2 sec and re-implement timerEvent to get timer events to close your messagebox.

    # startTimer(2000) // before showing message box

    #void <ur class>::timerEvent(QTimerEvent *event)
    {
    this->lMessage->close();
    }
    I hope it would help you. - Vikas

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    16

    Re: QMessageBox without buttons.

    Yes but still the OK button is displayed. I do not want the OK button to be shown on the screen. Is there any way to hide the OK button in QMessageBox

  5. #5
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: QMessageBox without buttons.

    Yes, simply set the buttons to 0:
    Code:
    QMessageBox m;
    m.setStandardButtons(0);

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    16

    Re: QMessageBox without buttons.

    Thank you. We managed to get the same functionality with the help of QLabel.

Similar Threads

  1. QMessageBox Icons to a Window
    By ras123 in forum Qt
    Replies: 8
    Last Post: 2010-08-11, 19:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×