Improve band combo box pop up list width management

This commit is contained in:
Bill Somerville 2021-06-24 19:13:27 +01:00
parent 31a4fac516
commit b241b913ba
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F
5 changed files with 54 additions and 5 deletions

View File

@ -238,6 +238,7 @@ set (wsjt_qt_CXXSRCS
Network/NetworkAccessManager.cpp Network/NetworkAccessManager.cpp
widgets/LazyFillComboBox.cpp widgets/LazyFillComboBox.cpp
widgets/CheckableItemComboBox.cpp widgets/CheckableItemComboBox.cpp
widgets/BandComboBox.cpp
) )
set (wsjt_qtmm_CXXSRCS set (wsjt_qtmm_CXXSRCS

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>635</width> <width>635</width>
<height>512</height> <height>523</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -1704,7 +1704,7 @@ p, li { white-space: pre-wrap; }
<customwidget> <customwidget>
<class>DisplayText</class> <class>DisplayText</class>
<extends>QTextBrowser</extends> <extends>QTextBrowser</extends>
<header>displaytext.h</header> <header>widgets/displaytext.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>

27
widgets/BandComboBox.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "BandComboBox.hpp"
#include <QAbstractItemView>
#include <QScrollBar>
#include <QDebug>
#include "models/FrequencyList.hpp"
BandComboBox::BandComboBox (QWidget * parent)
: QComboBox {parent}
{
}
// Fix up broken QComboBox item view rendering which doesn't allow for
// a vertical scroll bar in width calculations and ends up eliding the
// item text.
void BandComboBox::showPopup ()
{
auto minimum_width = view ()->sizeHintForColumn (FrequencyList_v2::frequency_mhz_column);
if (count () > maxVisibleItems ())
{
// for some as yet unknown reason, in FT8 mode the scrollbar
// width is oversize on the first call here
minimum_width += view ()->verticalScrollBar ()->width ();
}
view ()->setMinimumWidth (minimum_width);
QComboBox::showPopup ();
}

16
widgets/BandComboBox.hpp Normal file
View File

@ -0,0 +1,16 @@
#ifndef BAND_COMBO_BOX_HPP__
#define BAND_COMBO_BOX_HPP__
#include <QComboBox>
class BandComboBox
: public QComboBox
{
public:
explicit BandComboBox (QWidget * = nullptr);
private:
void showPopup () override;
};
#endif

View File

@ -644,7 +644,7 @@ QPushButton[state=&quot;ok&quot;] {
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QComboBox" name="bandComboBox"> <widget class="BandComboBox" name="bandComboBox">
<property name="toolTip"> <property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Select operating band or enter frequency in MHz or enter kHz increment followed by k.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Select operating band or enter frequency in MHz or enter kHz increment followed by k.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
@ -661,7 +661,7 @@ QPushButton[state=&quot;ok&quot;] {
<enum>QComboBox::NoInsert</enum> <enum>QComboBox::NoInsert</enum>
</property> </property>
<property name="sizeAdjustPolicy"> <property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum> <enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property> </property>
</widget> </widget>
</item> </item>
@ -3434,7 +3434,7 @@ Double-click to reset to the standard 73 message</string>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>DisplayText</class> <class>DisplayText</class>
<extends>QTextEdit</extends> <extends>QTextBrowser</extends>
<header>widgets/displaytext.h</header> <header>widgets/displaytext.h</header>
</customwidget> </customwidget>
<customwidget> <customwidget>
@ -3468,6 +3468,11 @@ Double-click to reset to the standard 73 message</string>
<extends>QPushButton</extends> <extends>QPushButton</extends>
<header>widgets/DoubleClickablePushButton.hpp</header> <header>widgets/DoubleClickablePushButton.hpp</header>
</customwidget> </customwidget>
<customwidget>
<class>BandComboBox</class>
<extends>QComboBox</extends>
<header>widgets/BandComboBox.hpp</header>
</customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>decodedTextBrowser</tabstop> <tabstop>decodedTextBrowser</tabstop>