Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set precise size of QPushButton?

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.

enter image description here

P.P.S. this line button->setStyleSheet("border: 1px solid black; background: white"); gives such effect (precise size)

enter image description here

like image 396
LmTinyToon Avatar asked Mar 17 '16 14:03

LmTinyToon


1 Answers

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

like image 130
IGHOR Avatar answered Sep 20 '22 01:09

IGHOR