mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-30 11:38:50 -07:00
Resize dialog size on high DPI monitors
This commit is contained in:
parent
aaaa67050c
commit
27cf98a962
26 changed files with 125 additions and 80 deletions
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "mainwindow.h"
|
||||
#include "ui_autoexpandabledialog.h"
|
||||
#include "utils.h"
|
||||
|
||||
AutoExpandableDialog::AutoExpandableDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
|
@ -68,30 +69,29 @@ QString AutoExpandableDialog::getText(QWidget *parent, const QString &title, con
|
|||
void AutoExpandableDialog::showEvent(QShowEvent *e)
|
||||
{
|
||||
// Overriding showEvent is required for consistent UI with fixed size under custom DPI
|
||||
// Show dialog
|
||||
QDialog::showEvent(e);
|
||||
// and resize textbox to fit the text
|
||||
|
||||
// NOTE: For some strange reason QFontMetrics gets more accurate
|
||||
// when called from showEvent. Only 6 symbols off instead of 11 symbols off.
|
||||
int textW = m_ui->textEdit->fontMetrics().width(m_ui->textEdit->text()) + 4;
|
||||
int wd = textW;
|
||||
// Show dialog and resize textbox to fit the text
|
||||
// NOTE: For unknown reason QFontMetrics gets more accurate when called from showEvent.
|
||||
int wd = m_ui->textEdit->fontMetrics().width(m_ui->textEdit->text()) + 4;
|
||||
|
||||
if (!windowTitle().isEmpty()) {
|
||||
int w = fontMetrics().width(windowTitle());
|
||||
if (w > wd)
|
||||
wd = w;
|
||||
// not really the font metrics in window title, so we enlarge it a bit,
|
||||
// including the small icon and close button width
|
||||
int w = fontMetrics().width(windowTitle()) * 1.8;
|
||||
wd = std::max(wd, w);
|
||||
}
|
||||
|
||||
if (!m_ui->textLabel->text().isEmpty()) {
|
||||
int w = m_ui->textLabel->fontMetrics().width(m_ui->textLabel->text());
|
||||
if (w > wd)
|
||||
wd = w;
|
||||
wd = std::max(wd, w);
|
||||
}
|
||||
|
||||
// Now resize the dialog to fit the contents
|
||||
// max width of text from either of: label, title, textedit
|
||||
// If the value is less than dialog default size, default size is used
|
||||
if (wd > width())
|
||||
resize(width() - m_ui->verticalLayout->sizeHint().width() + wd, height());
|
||||
if (wd > width()) {
|
||||
QSize size = {width() - m_ui->verticalLayout->sizeHint().width() + wd, height()};
|
||||
Utils::Gui::resize(this, size);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue