Results 1 to 5 of 5

Thread: QDialog margin and spacing

  1. #1
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    99
    Thanks
    11
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDialog margin and spacing

    I'm using solaris 5.8, Qt 4.2.2 and gcc 3.3 and have been trying to create a dialog with no margin or spacing for its child widgets. Unfortunately, things aren't going too well. It turns out that i only get the desired effect if i use a QWidget or QMainWindow instead of a QDialog. Could this be a bug in Qt?

    Below is some code that produces two windows, one being a QDialog and the other a QWidget. The QDialog behaves incorrectly, insisting on drawing a margin and spacing for the child widgets, while the QWidget has the desired behavior.

    Qt Code:
    1. #include <QApplication>
    2. #include <QDialog>
    3. #include <QVBoxLayout>
    4. #include <QPushButton>
    5.  
    6. int main(int argc, char** argv)
    7. {
    8. QApplication app(argc, argv);
    9.  
    10. //////////////////////////////////////////////////////////////////////
    11. // create a dialog with two buttons
    12.  
    13. QDialog diag;
    14. diag.setWindowFlags(Qt::Widget);
    15. diag.setWindowTitle("dialog");
    16. QVBoxLayout* layout = new QVBoxLayout();
    17. diag.setLayout(layout);
    18.  
    19. QSizePolicy policy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    20. QPushButton* button1 = new QPushButton("button1");
    21. button1->setSizePolicy(policy);
    22. layout->addWidget(button1);
    23.  
    24. QPushButton* button2 = new QPushButton("button2");
    25. button2->setSizePolicy(policy);
    26. layout->addWidget(button2);
    27.  
    28. layout->setMargin(0);
    29. layout->setSpacing(0);
    30.  
    31. diag.show();
    32.  
    33. //////////////////////////////////////////////////////////////////////
    34. // create a widget with two buttons
    35.  
    36. QWidget widg;
    37. widg.setWindowTitle("widget");
    38. layout = new QVBoxLayout();
    39. widg.setLayout(layout);
    40.  
    41. button1 = new QPushButton("buttonA");
    42. button1->setSizePolicy(policy);
    43. layout->addWidget(button1);
    44.  
    45. button2 = new QPushButton("buttonB");
    46. button2->setSizePolicy(policy);
    47. layout->addWidget(button2);
    48.  
    49. layout->setMargin(0);
    50. layout->setSpacing(0);
    51.  
    52. widg.show();
    53.  
    54. return app.exec();
    55. }
    To copy to clipboard, switch view to plain text mode 

    Please, can any of you confirm the incorrect behavior? Or maybe i'm alone out here on Solaris island?

    Thanks in advance!

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDialog margin and spacing

    Could you provide a screenshot? Which style are you using? Does it happen with other styles, for example:
    ./app -style plastique
    J-P Nurmi

  3. #3
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    99
    Thanks
    11
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog margin and spacing

    screenshot.jpg

    As you can see in the attached screenshot, the cde, motif and windows styles force the dialog to have a margin and spacing. It's most apparent in cde and motif. Cleanlooks, plastique and WindowsXp do not produce a noticable margin and spacing.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDialog margin and spacing

    Looks weird, indeed. I'd suggest opening a new task at the task-tracker.
    J-P Nurmi

  5. #5
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    99
    Thanks
    11
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog margin and spacing...Solved!

    Apparently, the discrepancy is due to the autodefault property:

    http://doc.trolltech.com/4.2/qpushbu...toDefault-prop

    And hats off to trolltech for their speedy reply to my query.

  6. The following user says thank you to TheRonin for this useful post:

    jpn (29th October 2007)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.