mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
try to adjust VNotebookSelector's popup's width to the content
This commit is contained in:
parent
ce1cefa793
commit
ee4bfb171a
@ -4,6 +4,8 @@
|
||||
#include <QListWidget>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
#include "vnotebook.h"
|
||||
#include "vconfigmanager.h"
|
||||
#include "dialog/vnewnotebookdialog.h"
|
||||
@ -361,5 +363,26 @@ void VNotebookSelector::showPopup()
|
||||
newNotebook();
|
||||
return;
|
||||
}
|
||||
resizeListWidgetToContent();
|
||||
QComboBox::showPopup();
|
||||
}
|
||||
|
||||
void VNotebookSelector::resizeListWidgetToContent()
|
||||
{
|
||||
static QRect screenRect = QGuiApplication::primaryScreen()->geometry();
|
||||
static int maxMinWidth = screenRect.width() < 400 ? screenRect.width() : screenRect.width() / 2;
|
||||
static int maxMinHeight = screenRect.height() < 400 ? screenRect.height() : screenRect.height() / 2;
|
||||
|
||||
int minWidth = 0;
|
||||
int minHeight = 0;
|
||||
if (m_listWidget->count() > 0) {
|
||||
// Width
|
||||
minWidth = m_listWidget->sizeHintForColumn(0);
|
||||
minWidth = qMin(minWidth, maxMinWidth);
|
||||
|
||||
// Height
|
||||
minHeight = m_listWidget->sizeHintForRow(0) * m_listWidget->count() + 10;
|
||||
minHeight = qMin(minHeight, maxMinHeight);
|
||||
}
|
||||
m_listWidget->setMinimumSize(minWidth, minHeight);
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ private:
|
||||
int indexOfListItem(const QListWidgetItem *p_item);
|
||||
// @p_index is the idnex of QComboBox.
|
||||
inline VNotebook *getNotebookFromComboIndex(int p_index);
|
||||
void resizeListWidgetToContent();
|
||||
|
||||
VNote *m_vnote;
|
||||
QVector<VNotebook *> &m_notebooks;
|
||||
|
Loading…
x
Reference in New Issue
Block a user