Home > other >  [original] about set the QDockWidget initial size
[original] about set the QDockWidget initial size

Time:09-30

Change: (sequence) influence on initialization, see in the end, the first set of test code: copying code int main (int arg c, char * argv []) {//... Omit create QApplication & amp; QDockWidget * pDockw=new CustomDockWidget QMainWindow process; MainWidow. AddDockWidget (Qt: : LeftDockWidgetArea, pDockw);//[A]} class CustomDockWidget: public QDockWidget {public: QSize sizeHint () const {//initializes the window size; Return QSize (500, 900); }}; In the position of the rewrite the content respectively, test: QSize (10, 900);//[1] QDockWidget. Width=73; QSize (100, 900);//[2] QDockWidget. Width=100; QSize (200, 900);//[3] QDockWidget. Width=200; Test results: in addition to the value of [1] is too small, is set width=73, other two tests in accordance with test results, i.e., the accurate shows the QDockWidget wide in the QMainWindow (" high "test), conclusion: in the case of no widget, using sizeHint initial size set is valid. The second set of test code: increase" "on the basis of the above code, the code is as follows: copying code [b] class MyWidget: public QFrame { public: QSize sizeHint () const { //initializes the window size; return QSize (500, 900); [C]// } }; main function increase ([A] location) : copying code { pw MyWidget *=new MyWidget; pDockw - & gt; SetWidget (pw); } for the smallest value in the location of the rewrite: QSize (10, 900); Objective: to reduce the QDockWidget set after the impact, in the location of the [C] rewrite the content respectively, test: QSize (80, 900);//[1] QDockWidget. Width=80; QSize (150, 900);//[2] QDockWidget. Width=150; QSize (500, 900);//[3] QDockWidget. Width=500; Confirmed: in the case of the width of the QDockWidget "tiny", its internal the size of the Widget, affect the QDockWidget final size, the third set of test: the above test process remains the same, this time will be in position to large value: QSize (600, 900); Purpose: to test the size of the QDockWidget is greater than the Widget size results. Results: QSize (80, 900);//[1] QDockWidget. Width=80; QSize (150, 900);//[2] QDockWidget. Width=150; QSize (500, 900);//[3] QDockWidget. Width=500; Indirect description: within the QDockWidget widget, and widgets have exact initial value, the QDockWidget initial value is no longer the final role. The fourth group test: goal: storage & amp; Restore the QDockWidget geometry information; Commented on before "MyWidget" code, namely: only QApplication & amp; QMainWindow & amp; QDockWidget 3. Use the QSettings do "storage & amp; Return ". The QSettings code is as follows: [definition:] QSettings Settings (" & lt; Literally 1 & gt;" , "& lt; Just 2 & gt;" ); [recovery:] copying code [b] [b] const QString key (" & lt; A unique name to access the corresponding & gt;" ); [/b] [/b] [b] [b] const QByteArray ba (Settings. The value (key + QLatin1String ("/geometry "). The toByteArray ()); [/b] [/b] [b] [b] restoreGeometry (ba); [/b] [/b] [storage:] copying code [b] [b] Settings. BeginGroup (" & lt; A unique name to access corresponding & gt;" ); [/b] [/b] [b] [b] Settings. The setValue (QLatin1String (" geometry "), saveGeometry ()); [/b] [/b] [b] [b] Settings. EndGroup (); : [/b] [/b] test within ~ CustomDockWidget call [storage]. After addDockWidget [back] test results: failure when remove normalGeometry=& gt; Data is invalid. The verification results: in ~ CustomDockWidget saveGeometry before (), access to copy the code [b] [b] QRect rect1=frameGeometry ();//effective [/b] [/b] [b] [b] QRect rect2=normalGeometry ();//invalid (0, 0, 1, 1) [/b] [/b] note: to prevent in the process of destructor normalGeometry is "dirty", instead of in app. The exec (); After the execution; Final conclusion: only when the QDockWidget to geometric structure of the effective storage. With five test: only for MyWidget storage geometry information; Test method: respectively in construction and the destructor MyWidget write [recovery] and [storage]. Run the test: -_ -!!!! Failure: (why not restore succeed? Track when the [out] frameGeometry () and normalGeometry (), data is correct. Only suspect "initial value" ~ ~ 6 groups of tests: have effectively recover the data, the cover the "initial value", namely: sizeHint returns [out] results; Run tests: (^ o ^) ~ ~ added: sequence to initialize the influence of the geometry information, divided into three things: a: set up the central widget, b: add toolwidget (dockwidget), c: show MainWindow, three sequence is not totally random, when b=& gt; C=& gt; The set when the failure (only this order),

CodePudding user response:

Use one line of code is good
 
ResizeDocks ({dock}, {200}, Qt: : Horizontal);
  • Related