×

Discussion Board

Results 1 to 3 of 3

Hybrid View

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    24

    widgets are not aligned well inside a QMainWIndow or QDialog

    There seems to be some issues since QT4.6.2 release where the widgets don't align well in QMainWindow and QDialog, seems like the spacing is lost. Ive attached an example program to show this issue and instructions below to reproduce.
    The alignments were fine in PR1.1 , it has changed in PR1.2
    Ive also provided links to some screenshots to explain the issue well.
    STEPS:
    =======
    Compile the example with qmake from /opt/qt4-maemo5/bin which is QT4.6 in PR1.1 and run on the device with QT4.6 libs from PR1.1 installed in /opt/qt4-maemo5/lib
    ~$: ldd TEMP2
    ....
    libQtGui.so.4 => /opt/qt4-maemo5/lib/libQtGui.so.4 (0x40142000)
    libQtCore.so.4 => /opt/qt4-maemo5/lib/libQtCore.so.4 (0x40bfd000)
    ....

    and this is the result
    http://bit.ly/bH2ApK

    Then
    Compile the example with qmake from /usr/bin which is QT4.6 in PR1.2 and run on the device with QT4.6 libs from PR1.2 installed in /usr/lib
    ~$: ldd TEMP2
    ....
    libQtGui.so.4 => /usr/lib/libQtGui.so.4 (0x40139000)
    libQtCore.so.4 => /usr/lib/libQtCore.so.4 (0x40bf4000)
    ....

    and you will see this
    http://bit.ly/bIpRi0

    I think some default alignments may have been changed in the styles.

    Thanks again for taking a look.

    Example.cpp
    Code:
    #include <QtGui>
    #include <QApplication>
    
    int main(int argc, char* argv[])
    {
        QApplication app(argc, argv);
    
        QDialog *dialog = new QDialog;
    
        QScrollArea *scroll = new QScrollArea;
        QWidget*    widget = new QWidget(scroll);
    
        // Currency code
        QLineEdit *currency = new QLineEdit(dialog);
    
        // Date format
        QStringList dateformatlist;
        dateformatlist << "dd-MM-yyyy" << "MM-dd-yyyy" << "dd-MMM-yyyy" << "MMM-dd-yyyy";
        QComboBox *dateformat = new QComboBox;
    
        // Graph Period
        QStringList periodlist;
        periodlist << "current day" << "current month" << "current week" << "current year";
        QComboBox *graphperiod = new QComboBox;
    
        dialog->setStyleSheet("QDialog { border: 2px solid #8f8f91; ; border-radius: 15px; }");
    
        QFormLayout *layout = new QFormLayout;
        layout->addRow("currency code : ", currency);
        layout->addRow("display date format : ", dateformat);
        layout->addRow("default reports period: ", graphperiod);
        widget->setLayout(layout);
    
        QHBoxLayout *mainlayout = new QHBoxLayout;
    
        scroll->setWidget(widget);
        mainlayout->addWidget(scroll, 0, Qt::AlignVCenter);
    
        dialog->setLayout(mainlayout);
        dialog->show();
    
        return app.exec();
    }

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: widgets are not aligned well inside a QMainWIndow or QDialog

    There is something wrong with calculation of background rectangle, so it overlaps with border. I've changed the code like this
    to workaround the issue
    Code:
    #include <QtGui>
    
    int main(int argc, char* argv[])
    {
        QApplication app(argc, argv);
        app.setStyleSheet("QScrollArea {padding: 3px 3px 3px 3px; border: 2px solid #8f8f91; ; border-radius: 15px;}");
        
        QLineEdit *currency = new QLineEdit;
        QComboBox *dateformat = new QComboBox;
        QComboBox *graphperiod = new QComboBox;
    
        QFormLayout *layout = new QFormLayout;
        layout->addRow("currency code : ", currency);
        layout->addRow("display date format : ", dateformat);
        layout->addRow("default reports period: ", graphperiod);
    
        QWidget *widget = new QWidget();
        widget->setLayout(layout);
    
        QScrollArea *scroll = new QScrollArea;
        scroll->setWidget(widget);
    
        QHBoxLayout *mainlayout = new QHBoxLayout;
        mainlayout->addWidget(scroll);
    
        QDialog *dialog = new QDialog;
        dialog->setLayout(mainlayout);
        dialog->show();
    
        return app.exec();
    }
    Note, in theory you don't need QScrollArea here.

    Just for a record, Ram reported the bug to Qt bug tracker
    http://bugreports.qt.nokia.com/browse/QTBUG-11135
    Last edited by divanov; 2010-06-01 at 11:44.

  3. #3
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: widgets are not aligned well inside a QMainWIndow or QDialog

    A bit better workaround fixing the root cause of the problem, wrong top content margin.
    Code:
    #include <QtGui>
    
    QLayout* layoutFactory()
    {
        QVBoxLayout *layout = new QVBoxLayout;
        for (int i = 0; i < 5; i++)
            layout->addWidget(new QPushButton("Button"));
        return layout;
    }
    
    int main(int argc, char* argv[])
    {
        QApplication app(argc, argv);
        app.setStyleSheet("QDialog {border: 2px solid white; border-radius: 15px}"
                          "QMainWindow {border: 2px solid white; border-radius: 15px}");
        int left, top, right, bottom;
    
        QWidget *widget = new QWidget;
        widget->setLayout(layoutFactory());
    
        QMainWindow win;
        win.setCentralWidget(widget);
    
        widget->layout()->getContentsMargins(&left, &top, &right, &bottom);
        qDebug() << left << top << right << bottom;
        widget->layout()->setContentsMargins (16, 8, 16, 8);
    
        win.show();
    
        QDialog dialog;
        dialog.setLayout(layoutFactory());
    
        dialog.layout()->getContentsMargins(&left, &top, &right, &bottom);
        qDebug() << left << top << right << bottom;
        dialog.layout()->setContentsMargins (16, 8, 16, 8);
    
        dialog.exec();
    
        return app.exec();
    }
    Last edited by divanov; 2010-06-02 at 11:13.

Similar Threads

  1. s60 widgets development
    By ambatisreedhar in forum Symbian
    Replies: 3
    Last Post: 2009-09-25, 14:41
  2. Announcing the Winners of the WidSets widgets coding contest
    By Maveric in forum Widsets Development
    Replies: 0
    Last Post: 2008-07-04, 10:05

Posting Permissions

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