Problem with QGridLayout column width
-
Windows Qt 5.15
I have a QGridLayout. Right now, it consists of one row with two columns. The first column contains an icon in a QLabel, the second column contains a QTextEdit. I'm trying to get the QTextEdit to be left aligned, right next to the icon.The grid is displayed properly in linux, but the QTextEdit is a bit to the right in windows. It appears that the problem is that the icon column is too wide in windows, leaving space between the icon and the text. Here is the current code for the icon and column.
I currently have the icon centered horizontally as that shows me that the problem is in the icon column, but the finished code will have the icon left aligned. But currently, that just makes it more difficult to see where the problem is. I have the stretch set. I've added fixed spacing (which didn't make a difference). Again, it shows up properly in linux with a fixed width column, but not in windows.
const auto pLayout = new QGridLayout; pLayout->setContentsMargins(0, 0, 0, 0); pLayout->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); pLayout->setSpacing(0); pLayout->setMargin(0); setLayout(pLayout); pLayout->setColumnStretch(0, 0); pLayout->setColumnStretch(1, 1); const auto pIconLabel = new QLabel; pIconLabel->setContentsMargins(0, 0, 0, 0); pIconLabel->setPixmap(pIcon.pixmap(QSize(30, 30))); pIconLabel->setFixedWidth(30); pIconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); pLayout->addWidget(pIconLabel, 0, 0, Qt::AlignHCenter | Qt::AlignVCenter);Edit: I removed the call to the obsolete setMargin. It didn't make a difference
-
Hi,
You should provide a complete minimal compilable example so people uses the same code as you to check your issue.
Which version of Windows are you on ?
Which exact version of Qt are you using ?
Please note that 5.15 has reached EOL so you should move on to Qt 6.