Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMessageBox too small
Forum Updated to NodeBB v4.3 + New Features

QMessageBox too small

Scheduled Pinned Locked Moved General and Desktop
14 Posts 6 Posters 23.1k Views 2 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.
  • S Offline
    S Offline
    Serenity
    wrote on last edited by
    #1

    Hello,

    I have a problem with the size of my QMessageBox.
    [code] QMessageBox msg(this);
    msg.setIconPixmap(QPixmap(":/error.svg"));
    msg.setText("No images loaded");
    msg.setInformativeText("There are no images in the list. Please create or load a project");
    msg.setStandardButtons(QMessageBox::Ok);
    msg.setDefaultButton(QMessageBox::Ok);
    msg.setFixedWidth(500);
    msg.exec();[/code]

    It is every time to small in the width and I don't know why. My parent widget is a QWidget with a minimum size.
    The function "msg.setFixedWidth(300);" has no effect, I can also change it to 800 and it has always a width of approx. 280px.

    I can also make a new class which inherits QDialog and write it by my own, but I would prefere to use QMessageBox.
    Can anybody tell me, why the size of my QMessageBox is so small?

    I am programming in Linux Mint 13 (MATE) with Qt4.8.1

    Thank you!

    1 Reply Last reply
    1
    • B Offline
      B Offline
      bootchk
      wrote on last edited by
      #2

      Aren't you tilting at windmills: fighting a problem that doesn't need fixing? That the dialog is functional is sufficient. Is "too small" a style issue, or a real problem to the user?

      I would guess that a QMessageBox, designed to be convenient to use and cross-platform, is smart enough to size itself so as to minimize hiding of other windows and so forth. So it seems reasonable that it might have overridden the QWidget.setFixedWidth() method, although the documents don't state that.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        leon.anavi
        wrote on last edited by
        #3

        This sounds strange. Although I did not find similar issues reported for Qt 4.8 at "jira":https://bugreports.qt-project.org it might be a bug.

        Anyway I found out "this proposition for a work around at qtcenter.org that you may try":http://www.qtcentre.org/threads/22298-QMessageBox-Controlling-the-width?p=113348#post113348:

        @
        QMessageBox msg(this);
        msg.setIconPixmap(QPixmap(":/error.svg"));
        msg.setText("No images loaded");
        msg.setInformativeText("There are no images in the list. Please create or load a project");
        msg.setStandardButtons(QMessageBox::Ok);
        msg.setDefaultButton(QMessageBox::Ok);

        QSpacerItem* horizontalSpacer = new QSpacerItem(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
        QGridLayout* layout = (QGridLayout*)msg.layout();
        layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
        msg.exec();
        @

        http://anavi.org/

        1 Reply Last reply
        2
        • S Offline
          S Offline
          Serenity
          wrote on last edited by
          #4

          Thank you, it seems to work with your work around.
          But I am still wondering, why it doesn't resize by itself.

          I have also another similar program, where the QMessageBox works well and I tried to find out their difference with no result. It's a little bit strange.

          @bootchk: I am only wondering, why the size of the window is too small in the width. Maybe somebody knows the problem. I thought also, that it could be something related to the parent widget, but also without that, the window is to small in the width. And inanother similar program, it works well.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            leon.anavi
            wrote on last edited by
            #5

            [quote author="Serenity" date="1360759711"]Thank you, it seems to work with your work around.
            But I am still wondering, why it doesn't resize by itself.
            [/quote]

            I have no idea with setFixedWidth didn't work as expected too. In fact the work around is not mine. As I said I found it at "an old thread at Qt Centre":http://www.qtcentre.org/threads/22298-QMessageBox-Controlling-the-width?p=113348#post113348

            http://anavi.org/

            1 Reply Last reply
            0
            • W Offline
              W Offline
              Wonson
              wrote on last edited by
              #6

              After 3 years, it is still not fixed

              mrjjM 1 Reply Last reply
              1
              • W Wonson

                After 3 years, it is still not fixed

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Wonson
                well maybe it was never reported ?

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DougyDrumz
                  wrote on last edited by
                  #8

                  Has anybody found a solutions to this? I tried http://www.qtcentre.org/threads/22298-QMessageBox-Controlling-the-width?p=113348#post113348 to no avail. Is seems my QMessageBox won't expand beyond it's internal maximum width.

                  Dougy Drumz

                  mrjjM 1 Reply Last reply
                  0
                  • D DougyDrumz

                    Has anybody found a solutions to this? I tried http://www.qtcentre.org/threads/22298-QMessageBox-Controlling-the-width?p=113348#post113348 to no avail. Is seems my QMessageBox won't expand beyond it's internal maximum width.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @DougyDrumz
                    hi this does work for me

                    #include <QMessageBox>
                    #include <QGridLayout>
                    #include <QSpacerItem>
                    
                    void MainWindow::on_pushButton_released()
                    {
                    
                        QMessageBox msg;
                        msg.setIconPixmap(QPixmap(":/error.svg"));
                        msg.setText("No images loaded");
                        msg.setInformativeText("There are no images in the list. Please create or load a project");
                        msg.setStandardButtons(QMessageBox::Ok);
                        msg.setDefaultButton(QMessageBox::Ok);
                        QSpacerItem* horizontalSpacer = new QSpacerItem(800, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
                        QGridLayout* layout = (QGridLayout*)msg.layout();
                        layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
                        msg.exec();
                    }
                    
                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DougyDrumz
                      wrote on last edited by
                      #10

                      This doesn't work for me. One thing I've noticed: You're opening this QMessageBox in a QMainWindow. My QMessageBox is opened in main. This is because I open the QMessageBox using an executable from the command line. It's not tied to any app. Could that be an issue? If it helps, I'm running Qt 4.6.2 on RHEL 6 machine.

                      Dougy Drumz

                      mrjjM 1 Reply Last reply
                      0
                      • D DougyDrumz

                        This doesn't work for me. One thing I've noticed: You're opening this QMessageBox in a QMainWindow. My QMessageBox is opened in main. This is because I open the QMessageBox using an executable from the command line. It's not tied to any app. Could that be an issue? If it helps, I'm running Qt 4.6.2 on RHEL 6 machine.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #11

                        @DougyDrumz
                        win 7, qt 5.5
                        well im not using "this" from mainwindow ,
                        so should be same as in main.cpp
                        Let me try.
                        update:
                        also works from main.

                        Maybe its diff between win and linux. But looking at code it seems that
                        its build with qt widgets so should function the same.

                        1 Reply Last reply
                        0
                        • mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          hi
                          could you try for test to run this

                          #include <QList>
                          void Pop() {
                           QMessageBox msg;
                           msg.setIconPixmap(QPixmap(":/error.svg"));
                           msg.setText("No images loaded");
                           msg.setInformativeText("There are no images in the list. Please create or load a project");
                           msg.setStandardButtons(QMessageBox::Ok);
                           msg.setDefaultButton(QMessageBox::Ok);
                           QList<QObject*> widgets = msg.findChildren<QObject*>();
                           for (int var = 0; var < widgets.size(); ++var) {
                             qDebug() << widgets[var]->objectName() << widgets[var]->metaObject()->className();
                           }
                           msg.exec();
                          }
                          

                          its lists all objects.
                          my list is
                          "qt_msgboxex_icon_label" QLabel
                          "qt_msgbox_label" QLabel
                          "qt_msgbox_buttonbox" QDialogButtonBox
                          "" QHBoxLayout
                          "" QPushButton
                          "" QGridLayout
                          "qt_msgbox_informativelabel" QLabel
                          just too see if inner layout is different for you.

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            DougyDrumz
                            wrote on last edited by
                            #13

                            Same objects, different order:

                            "" QGridLayout
                            "qt_msgboxex_icon_label" QLabel
                            "qt_msgbox_label" QLabel
                            "qt_msgbox_buttonbox" QDialogButtonBox
                            "" QHBoxLayout
                            "" QPushButton
                            "qt_msgbox_informativelabel" QLabel

                            Dougy Drumz

                            mrjjM 1 Reply Last reply
                            0
                            • D DougyDrumz

                              Same objects, different order:

                              "" QGridLayout
                              "qt_msgboxex_icon_label" QLabel
                              "qt_msgbox_label" QLabel
                              "qt_msgbox_buttonbox" QDialogButtonBox
                              "" QHBoxLayout
                              "" QPushButton
                              "qt_msgbox_informativelabel" QLabel

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @DougyDrumz
                              Ok, nothing exciting there.
                              looking at the code in qmessagebox.cpp i see nothing that should it do different
                              on linux.
                              Have you looked in your version ?
                              seems like it's a lost cause as most of the stuff is in private.

                              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