Add minimal support for ellipsization to wxQt wxStaticText

Set the visible label to the ellipsized value, if necessary.

Also call AutoResizeIfNecessary() for consistency with the other ports.
This commit is contained in:
Vadim Zeitlin
2019-07-07 15:54:14 +02:00
parent 63a40a09b2
commit 958521183a
2 changed files with 20 additions and 2 deletions

View File

@@ -31,10 +31,13 @@ public:
const wxString &name = wxStaticTextNameStr ); const wxString &name = wxStaticTextNameStr );
virtual void SetLabel(const wxString& label) wxOVERRIDE; virtual void SetLabel(const wxString& label) wxOVERRIDE;
virtual wxString GetLabel() const wxOVERRIDE;
virtual QWidget *GetHandle() const wxOVERRIDE; virtual QWidget *GetHandle() const wxOVERRIDE;
protected:
virtual wxString WXGetVisibleLabel() const wxOVERRIDE;
virtual void WXSetVisibleLabel(const wxString& str) wxOVERRIDE;
private: private:
QLabel *m_qtLabel; QLabel *m_qtLabel;

View File

@@ -59,11 +59,26 @@ bool wxStaticText::Create(wxWindow *parent,
} }
void wxStaticText::SetLabel(const wxString& label) void wxStaticText::SetLabel(const wxString& label)
{
// If the label doesn't really change, avoid flicker by not doing anything.
if ( label == m_labelOrig )
return;
// save the label in m_labelOrig with both the markup (if any) and
// the mnemonics characters (if any)
m_labelOrig = label;
WXSetVisibleLabel(GetEllipsizedLabel());
AutoResizeIfNecessary();
}
void wxStaticText::WXSetVisibleLabel(const wxString& label)
{ {
m_qtLabel->setText( wxQtConvertString( label ) ); m_qtLabel->setText( wxQtConvertString( label ) );
} }
wxString wxStaticText::GetLabel() const wxString wxStaticText::WXGetVisibleLabel() const
{ {
return wxQtConvertString( m_qtLabel->text() ); return wxQtConvertString( m_qtLabel->text() );
} }