From a2674fa9de25af1dd12f648df2782d08404a13ad Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 1 Jul 2018 11:07:37 +0200 Subject: [PATCH] Created combo box without arrow --- sdrgui/CMakeLists.txt | 2 ++ sdrgui/gui/comboboxnoarrow.cpp | 33 ++++++++++++++++++++++++++++ sdrgui/gui/comboboxnoarrow.h | 39 ++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 sdrgui/gui/comboboxnoarrow.cpp create mode 100644 sdrgui/gui/comboboxnoarrow.h diff --git a/sdrgui/CMakeLists.txt b/sdrgui/CMakeLists.txt index 4f6289690..401f3b677 100644 --- a/sdrgui/CMakeLists.txt +++ b/sdrgui/CMakeLists.txt @@ -14,6 +14,7 @@ set(sdrgui_SOURCES gui/commanditem.cpp gui/commandkeyreceiver.cpp gui/commandoutputdialog.cpp + gui/comboboxnoarrow.cpp gui/crightclickenabler.cpp gui/cwkeyergui.cpp gui/editcommanddialog.cpp @@ -73,6 +74,7 @@ set(sdrgui_HEADERS gui/commanditem.h gui/commandkeyreceiver.h gui/commandoutputdialog.h + gui/comboboxnoarrow.h gui/crightclickenabler.h gui/cwkeyergui.h gui/editcommanddialog.h diff --git a/sdrgui/gui/comboboxnoarrow.cpp b/sdrgui/gui/comboboxnoarrow.cpp new file mode 100644 index 000000000..327b9891e --- /dev/null +++ b/sdrgui/gui/comboboxnoarrow.cpp @@ -0,0 +1,33 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2018 F4EXB // +// written by Edouard Griffiths // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include + +#include "comboboxnoarrow.h" + +void ComboBoxNoArrow::paintEvent (QPaintEvent *ev __attribute__((unused))) +{ + QPainter p; + p.begin (this); + QStyleOptionComboBox opt; + opt.initFrom (this); + style()->drawPrimitive (QStyle::PE_PanelButtonBevel, &opt, &p, this); + style()->drawPrimitive (QStyle::PE_PanelButtonCommand, &opt, &p, this); + style()->drawItemText (&p, rect(), Qt::AlignCenter, palette(), isEnabled(), currentText()); + p.end(); +} + diff --git a/sdrgui/gui/comboboxnoarrow.h b/sdrgui/gui/comboboxnoarrow.h new file mode 100644 index 000000000..4974a61be --- /dev/null +++ b/sdrgui/gui/comboboxnoarrow.h @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2018 F4EXB // +// written by Edouard Griffiths // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef SDRGUI_GUI_COMBOBOXNOARROW_H_ +#define SDRGUI_GUI_COMBOBOXNOARROW_H_ + +#include + +/////////////////////////////////////////////////////////////////////////////////////////////////// +/// This class is a custom QComboBox which does NOT display the down arrow. The down arrow takes +/// a lot of real estate when you're trying to make them narrow. So much real estate that you can't +/// see short lines of text such as "CH 1" without the digit cut off. The only thing that this +/// custom widget does is to override the paint function. The new paint function draws the combo +/// box (using all style sheet info) without the down arrow. +/////////////////////////////////////////////////////////////////////////////////////////////////// +class ComboBoxNoArrow : public QComboBox +{ + Q_OBJECT +public: + ComboBoxNoArrow (QWidget *parent) : QComboBox(parent) {} + virtual ~ComboBoxNoArrow() {} + void paintEvent (QPaintEvent *ev); +}; + +#endif /* SDRGUI_GUI_COMBOBOXNOARROW_H_ */