QPlainTextEdit resize() does not seem to work
I'm using a QPlainTextEdit as log viewer.
Now I would like to adjust the application Dialog size so I can fit at 80 chars on a single line.
My idea was to calculate the numbers of pixels to display 80 chars and set the with of my QPlainText to this size in the constructor of my dialog.
This is a part of my dialog constructor:
QFontMetrics FontMetrics(ui->TextEditSerialOutput->font()); int PixelWidth = FontMetrics.width("012345678901234567890123456789012345678901234567890123456789012345678901234567890"); ui->TextEditSerialOutput->resize(PixelWidth,ui->TextEditSerialOutput->height());
But this has no effect, my dialog width is not changing.
I could also resize my dialog but then I need to know the size of my dialog and the size of my QPlainTextEdit but the size() does not seem to give correct values...
WriteLog("Dialog width : "+QString::number(this->size().width())+"\n");
WriteLog("QPlainTextEdit width : "+QString::number(ui->TextEditSerialOutput->size().width())+"\n");
Dialog width : 255
QPlainTextEdit width : 100
while this is my gui:
"Screenshot of my Dialog":https://www.dropbox.com/s/veh3u11kxzai2oh/nstcGui.png?dl=0
Hi and welcome to devnet,
If you want your widget to have a precise size you should rather use setFixedSize or in your case setFixedWidth.