On 13/03/2017 18:12, Black Michael wrote:
Yeah...I'm so used to WYSIWYG design that the layout management in Qt feels strange and non-intuitive....need more practice like this.

Anyways...I had tried a QWidget and apparently didn't do it right...it now behaves correctly.. Had to do a little tweaking on the vertical size to keep the graph from changing vertical positioning when the controls were toggled but looks good now.

https://www.dropbox.com/s/mgp87np3e9iacw6/fastgraph.patch?dl=1

Hi Mike,

there are still lots of issues, not necessarily new, the fast plot UI was a bit messy before you started. I suggest you work through the list below an then compare with the patch attached which is my result.

This is what I have done:

1. Using this-> in class member functions is unnecessary and
   non-idiomatic. Just using it on member functions even more so.
2. QWdiget has a member function QWidget::setVisibility(bool) which is
   more appropriate when you already have a boolean variable that
   visibility is conditional on. I.e. no need to use QWidget::hide()
   and QWidget::show() in a conditional statement.
3. When overriding an inherited virtual method modern C++ has the
   keyword `override` that shows your intent to override a virtual
   method. There is no need to declare the method virtual again, the
   compiler knows that, what the compiler needs to know is that you
   were aware and intended to override the base class implementation.
4. There is no need to change the fast graph dialog minimum size
   property nor to call QWidget::adjustSize(), once the layouts are
   done properly the default "Preferred" size policy will do that
   automatically.
5. To get a fixed size widget you simply need to set the layout size
   constraint to "SetFixedSize" for the outermost layout. That will let
   the QDialog be exactly the sum of its contained widgets size hints
   and offer no resizing handles to the user.
6. Given the above two points, there is no need for a member function
   to change the controls visibility -- simply change the
   controls_widget visibility.
7. There is no need for a member variable to store the controls
   visibility, the visibility status itself is just fine for that.
8. The toggling of the controls visibility is ugly, it only needs to be
   toggled in the CTRL+M handler.
9. In the UI, firstly I examined the layouts on the original fast graph
   UI. This is to work out the necessary layout margins and spacing. I
   see margins{2,2,2,2} and spacing 2 on the top level layout. I see
   margins {0,0,0,0} and spacing 2 on the redundant vertical layout
   `verticalLayout`. I see margins {0,0,0,0} and spacing 6 on the
   horizontal layout `horizontalLayout_3` managing the controls. We
   want to end up with a tidier equivalence to these.
10. The contained QVBoxLayout called `verticalLayout` is redundant. I
   deleted it by right-clicking the redundant layout object
   `verticalLayout` and selecting "Layout->Break Layout".
11. There is a horizontal layout now contained in the `FastGraph`
   vertical layout, it too is redundant and can also be removed in the
   same way as per the change above above. The new QWidget to contain
   the controls will do the same job.
12. The top level QDialog window (FastGraph) can have a layout that does
   the required vertical layout of the graph and controls. This is done
   by right-clicking the top level widget and selecting "Layout->Lay
   Out Vertically".
13. Moving to the new QWidget called `widget`, firstly I renamed it as
   `controls_widget` which is more meaningful. I also changed the
   reference in the code to match.
14. The new widget contains a redundant QHBoxLayout `horizontalLayout`
   which can be removed by right-clicking it and selecting
   "Layout->Break Layout"
15. The new `controls_widget` QWidget has no top level layout. You can
   see this from the red "no-entry" icon on top of its icon in the
   Designer object browser. I right-clicked it and selected
   "Layout->Lay Out Horizontally".
16. To get the same tight layout as before the margins for the
   `controls_widget` can be adjusted to {2,2,2,2}, the same needs
   setting on the layout of the top level widget `FastGraph`.

The above steps should get you basically the same layout as original. The object browser should look like:

with the `FastGraph` layout properties like this:

and the `controls_widget` layout properties looking like this:


Next I address the size policies and maximum sizes. This is mainly a clean up exercise.

We are looking for a fixed size top level widget, with that handled automatically by the layout size constraint above we can leave everything else at default for the top level widget, like this:


The controls widget need not specified policy nor sizing, the defaults are fine, like this:


73
Bill
G4WJS.
diff --git a/fastgraph.cpp b/fastgraph.cpp
index b164e8f..11fb379 100644
--- a/fastgraph.cpp
+++ b/fastgraph.cpp
@@ -12,14 +12,14 @@ FastGraph::FastGraph(QSettings * settings, QWidget *parent) 
:
   QDialog {parent, Qt::Window | Qt::WindowTitleHint |
            Qt::WindowCloseButtonHint |
            Qt::WindowMinimizeButtonHint},
-  m_settings (settings),
-  ui(new Ui::FastGraph)
+  m_settings {settings},
+  m_ave {40},
+  ui {new Ui::FastGraph}
 {
   ui->setupUi(this);
   setWindowTitle (QApplication::applicationName () + " - " + tr ("Fast 
Graph"));
   installEventFilter(parent);                   //Installing the filter
   ui->fastPlot->setCursor(Qt::CrossCursor);
-  m_ave=40;
 
 //Restore user's settings
   m_settings->beginGroup("FastGraph");
@@ -30,6 +30,7 @@ FastGraph::FastGraph(QSettings * settings, QWidget *parent) :
   ui->gainSlider->setValue(ui->fastPlot->m_plotGain);
   ui->fastPlot->setGreenZero(m_settings->value("GreenZero", 0).toInt());
   ui->greenZeroSlider->setValue(ui->fastPlot->m_greenZero);
+  ui->controls_widget->setVisible (!m_settings->value("HideControls", 
false).toBool ());
   m_settings->endGroup();
 
   connect (ui->fastPlot, &FPlotter::fastPick, this, &FastGraph::fastPick);
@@ -55,6 +56,7 @@ void FastGraph::saveSettings()
   m_settings->setValue("PlotGain",ui->fastPlot->m_plotGain);
   m_settings->setValue("GreenZero",ui->fastPlot->m_greenZero);
   m_settings->setValue("GreenGain",ui->fastPlot->m_greenGain);
+  m_settings->setValue("HideControls",!ui->controls_widget->isVisible ());
   m_settings->endGroup();
 }
 
@@ -105,3 +107,17 @@ void FastGraph::setMode(QString mode)                      
        //setMode
 {
   ui->fastPlot->setMode(mode);
 }
+
+void FastGraph::keyPressEvent(QKeyEvent *e)
+{
+  switch(e->key())
+  {
+  case Qt::Key_M:
+    if(e->modifiers() & Qt::ControlModifier) {
+      ui->controls_widget->setVisible (!ui->controls_widget->isVisible ());
+    }
+    break;
+  default:
+    QDialog::keyPressEvent (e);
+  }
+}
diff --git a/fastgraph.h b/fastgraph.h
index b7671b3..d19bdab 100644
--- a/fastgraph.h
+++ b/fastgraph.h
@@ -16,6 +16,7 @@ class FastGraph : public QDialog
 
 protected:
   void closeEvent (QCloseEvent *) override;
+  void keyPressEvent( QKeyEvent *e ) override;
 
 public:
   explicit FastGraph(QSettings *, QWidget *parent = 0);
diff --git a/fastgraph.ui b/fastgraph.ui
index 3ce550c..773c223 100644
--- a/fastgraph.ui
+++ b/fastgraph.ui
@@ -1,257 +1,238 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>FastGraph</class>
- <widget class="QDialog" name="FastGraph">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>710</width>
-    <height>250</height>
-   </rect>
-  </property>
-  <property name="sizePolicy">
-   <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
-    <horstretch>0</horstretch>
-    <verstretch>0</verstretch>
-   </sizepolicy>
-  </property>
-  <property name="minimumSize">
-   <size>
-    <width>710</width>
-    <height>250</height>
-   </size>
-  </property>
-  <property name="maximumSize">
-   <size>
-    <width>710</width>
-    <height>250</height>
-   </size>
-  </property>
-  <property name="windowTitle">
-   <string>Fast Graph</string>
-  </property>
-  <layout class="QVBoxLayout" name="verticalLayout_2">
-   <property name="spacing">
-    <number>2</number>
-   </property>
-   <property name="leftMargin">
-    <number>2</number>
-   </property>
-   <property name="topMargin">
-    <number>2</number>
-   </property>
-   <property name="rightMargin">
-    <number>2</number>
-   </property>
-   <property name="bottomMargin">
-    <number>2</number>
-   </property>
-   <item>
-    <layout class="QVBoxLayout" name="verticalLayout">
-     <property name="spacing">
-      <number>2</number>
-     </property>
-     <item>
-      <widget class="FPlotter" name="fastPlot">
-       <property name="enabled">
-        <bool>true</bool>
-       </property>
-       <property name="sizePolicy">
-        <sizepolicy hsizetype="Fixed" vsizetype="Expanding">
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="minimumSize">
-        <size>
-         <width>703</width>
-         <height>220</height>
-        </size>
-       </property>
-       <property name="maximumSize">
-        <size>
-         <width>703</width>
-         <height>220</height>
-        </size>
-       </property>
-       <property name="frameShape">
-        <enum>QFrame::StyledPanel</enum>
-       </property>
-       <property name="frameShadow">
-        <enum>QFrame::Sunken</enum>
-       </property>
-       <property name="lineWidth">
-        <number>1</number>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <layout class="QHBoxLayout" name="horizontalLayout_3">
-       <property name="spacing">
-        <number>6</number>
-       </property>
-       <item>
-        <spacer name="horizontalSpacer_2">
-         <property name="orientation">
-          <enum>Qt::Horizontal</enum>
-         </property>
-         <property name="sizeType">
-          <enum>QSizePolicy::Expanding</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>20</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
-       <item>
-        <widget class="QSlider" name="gainSlider">
-         <property name="toolTip">
-          <string>Waterfall gain</string>
-         </property>
-         <property name="minimum">
-          <number>-60</number>
-         </property>
-         <property name="maximum">
-          <number>140</number>
-         </property>
-         <property name="pageStep">
-          <number>40</number>
-         </property>
-         <property name="orientation">
-          <enum>Qt::Horizontal</enum>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <spacer name="horizontalSpacer_7">
-         <property name="orientation">
-          <enum>Qt::Horizontal</enum>
-         </property>
-         <property name="sizeType">
-          <enum>QSizePolicy::Preferred</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>20</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
-       <item>
-        <widget class="QSlider" name="zeroSlider">
-         <property name="toolTip">
-          <string>Waterfall zero</string>
-         </property>
-         <property name="minimum">
-          <number>-60</number>
-         </property>
-         <property name="maximum">
-          <number>120</number>
-         </property>
-         <property name="value">
-          <number>60</number>
-         </property>
-         <property name="orientation">
-          <enum>Qt::Horizontal</enum>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <spacer name="horizontalSpacer">
-         <property name="orientation">
-          <enum>Qt::Horizontal</enum>
-         </property>
-         <property name="sizeType">
-          <enum>QSizePolicy::Preferred</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>20</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
-       <item>
-        <widget class="QSlider" name="greenZeroSlider">
-         <property name="toolTip">
-          <string>Spectrum zero</string>
-         </property>
-         <property name="minimum">
-          <number>-100</number>
-         </property>
-         <property name="maximum">
-          <number>160</number>
-         </property>
-         <property name="value">
-          <number>30</number>
-         </property>
-         <property name="orientation">
-          <enum>Qt::Horizontal</enum>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <spacer name="horizontalSpacer_3">
-         <property name="orientation">
-          <enum>Qt::Horizontal</enum>
-         </property>
-         <property name="sizeType">
-          <enum>QSizePolicy::Preferred</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>20</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
-       <item>
-        <widget class="QPushButton" name="pbAutoLevel">
-         <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Set reasonable 
levels for gain and zero sliders.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-         </property>
-         <property name="text">
-          <string>Auto Level</string>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <spacer name="horizontalSpacer_5">
-         <property name="orientation">
-          <enum>Qt::Horizontal</enum>
-         </property>
-         <property name="sizeType">
-          <enum>QSizePolicy::Expanding</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>20</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
-      </layout>
-     </item>
-    </layout>
-   </item>
-  </layout>
- </widget>
- <customwidgets>
-  <customwidget>
-   <class>FPlotter</class>
-   <extends>QFrame</extends>
-   <header>fastplot.h</header>
-   <container>1</container>
-  </customwidget>
- </customwidgets>
- <resources/>
- <connections/>
-</ui>
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>FastGraph</class>
+ <widget class="QDialog" name="FastGraph">
+  <property name="windowTitle">
+   <string>Fast Graph</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="spacing">
+    <number>2</number>
+   </property>
+   <property name="sizeConstraint">
+    <enum>QLayout::SetFixedSize</enum>
+   </property>
+   <property name="leftMargin">
+    <number>2</number>
+   </property>
+   <property name="topMargin">
+    <number>2</number>
+   </property>
+   <property name="rightMargin">
+    <number>2</number>
+   </property>
+   <property name="bottomMargin">
+    <number>2</number>
+   </property>
+   <item>
+    <widget class="FPlotter" name="fastPlot">
+     <property name="enabled">
+      <bool>true</bool>
+     </property>
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Fixed" vsizetype="Expanding">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="minimumSize">
+      <size>
+       <width>703</width>
+       <height>220</height>
+      </size>
+     </property>
+     <property name="maximumSize">
+      <size>
+       <width>703</width>
+       <height>220</height>
+      </size>
+     </property>
+     <property name="frameShape">
+      <enum>QFrame::StyledPanel</enum>
+     </property>
+     <property name="frameShadow">
+      <enum>QFrame::Sunken</enum>
+     </property>
+     <property name="lineWidth">
+      <number>1</number>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QWidget" name="controls_widget" native="true">
+     <layout class="QHBoxLayout" name="horizontalLayout">
+      <property name="leftMargin">
+       <number>2</number>
+      </property>
+      <property name="topMargin">
+       <number>2</number>
+      </property>
+      <property name="rightMargin">
+       <number>2</number>
+      </property>
+      <property name="bottomMargin">
+       <number>2</number>
+      </property>
+      <item>
+       <spacer name="horizontalSpacer_2">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::Expanding</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>99</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item>
+       <widget class="QSlider" name="gainSlider">
+        <property name="toolTip">
+         <string>Waterfall gain</string>
+        </property>
+        <property name="minimum">
+         <number>-60</number>
+        </property>
+        <property name="maximum">
+         <number>140</number>
+        </property>
+        <property name="pageStep">
+         <number>40</number>
+        </property>
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <spacer name="horizontalSpacer_7">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::Preferred</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>20</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item>
+       <widget class="QSlider" name="zeroSlider">
+        <property name="toolTip">
+         <string>Waterfall zero</string>
+        </property>
+        <property name="minimum">
+         <number>-60</number>
+        </property>
+        <property name="maximum">
+         <number>120</number>
+        </property>
+        <property name="value">
+         <number>60</number>
+        </property>
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::Preferred</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>20</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item>
+       <widget class="QSlider" name="greenZeroSlider">
+        <property name="toolTip">
+         <string>Spectrum zero</string>
+        </property>
+        <property name="minimum">
+         <number>-100</number>
+        </property>
+        <property name="maximum">
+         <number>160</number>
+        </property>
+        <property name="value">
+         <number>30</number>
+        </property>
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <spacer name="horizontalSpacer_3">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::Preferred</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>20</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item>
+       <widget class="QPushButton" name="pbAutoLevel">
+        <property name="toolTip">
+         <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Set reasonable 
levels for gain and zero sliders.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+        </property>
+        <property name="text">
+         <string>Auto Level</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <spacer name="horizontalSpacer_5">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::Expanding</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>99</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>FPlotter</class>
+   <extends>QFrame</extends>
+   <header>fastplot.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
wsjt-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wsjt-devel

Reply via email to