I have SignatureEditorForm class, which inherits QDialog class:
SignatureEditorForm(QWidget* parent_widget) : QDialog(parent_widget)
{
resize(SIGNATURE_EDITOR_SIZE);
setWindowTitle(QString("Signature Editor"));
setWindowFlags(Qt::Window | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowCloseButtonHint);
setModal(true);
{
QPushButton* const button = new QPushButton(QString("<"), this);
const QSize BUTTON_SIZE = QSize(22, 22);
button->resize(BUTTON_SIZE);
}
}
It contains QPushButton which has size (width: 22, height: 22) and "<" caption. I have such picture of this widget (SignatureEditorForm). QPushButton has size (width: 20, height: 20). How can I set precise size of button?
P.S. I tried to use setMinimumSize, but it has not effects.
P.P.S. this line button->setStyleSheet("border: 1px solid black; background: white"); gives such effect (precise size)
QWidget::setFixedSize
This and other methods works fine to set exact size of QWidget.
But your problem is not in Qt, it in Windows Styling.
Actual size of widget is exact, but Windows reserve space on borders for animations, so it looks smaller than you expect.
To fix it you need to write own style like this:
button->setStyleSheet("border: 1px solid black; background: white");
Or use any of styles available here:
http://doc.qt.io/qt-5/gallery.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With