[Interest] Incorrect widget sizes on Windows?

Murphy, Sean smurphy at walbro.com
Wed Oct 2 20:18:33 CEST 2019


I'm encountering an odd widget sizing difference on Windows, namely if I have a QPushButton and a QComboBox together in a horizontal layout, and I set them both to have the same fixed height, the do not appear to have the same height - the combobox appears correct, but the push button is a couple pixels shorter:
[cid:image003.jpg at 01D5792C.44563540]

The exact same code running on Linux produces what I'd expect - both widgets have the same height:
[cid:image004.jpg at 01D5792C.44563540]

Sample code:
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QPushButton* pb = new QPushButton("Push Me");
    pb->setFixedHeight(35);

    QComboBox* cmb = new QComboBox();
    cmb->addItem("A");
    cmb->addItem("B");
    cmb->addItem("C");
    cmb->setFixedHeight(35);

    QTableWidget* table = new QTableWidget(3,2);

    QHBoxLayout* hbox = new QHBoxLayout();
    hbox->addWidget(pb);
    hbox->addWidget(cmb);
    hbox->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Preferred));

    QVBoxLayout* vbox = new QVBoxLayout();
    vbox->addItem(hbox);
    vbox->addWidget(table);

    QWidget* w = new QWidget(this);
    w->setLayout(vbox);

    setCentralWidget(w);
}

Windows machine is running Windows 10 Pro.
Linux machine is Elementary OS 5.0
Both programs are Qt 5.12.3, 64 bit.



This message has been scanned for malware by Forcepoint. www.forcepoint.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20191002/e1ceebb1/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.jpg
Type: image/jpeg
Size: 11777 bytes
Desc: image003.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20191002/e1ceebb1/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.jpg
Type: image/jpeg
Size: 12026 bytes
Desc: image004.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20191002/e1ceebb1/attachment-0001.jpg>


More information about the Interest mailing list