"QT5 Development and examples" 17, a dialog box coordinates the parameter display

Source: Internet
Author: User

The coordinate parameter of a dialog box shows an introduction

This is to get the length and width of the dialog, coordinates of each point, relative coordinates, relative coordinates of the parent window, relative to the coordinates of the desktop.


Code Geometry.h

/*** Book: "QT5 Development and examples" * Function: Display the coordinate information of the dialog box, parameter information * file: geometry.cpp* time: January 20, 2015 20:19:35* Author: cutter_point*/#ifndef geometry_h# Define Geometry_h#include <QDialog> #include <QLabel> #include <qgridlayout>class geometry:public  qdialog{q_objectpublic:geometry (Qwidget *parent = 0);  ~geometry ();     Display of updated data void Updatelabel ();p Rivate:qlabel *xlabel;  Represents the initial x-coordinate of the dialog box horizontal-----> Qlabel *xvaluelabel;   Qlabel *ylabel;  Represents the first y-coordinate of the dialog box with the vertical down arrow qlabel *yvaluelabel;   Qlabel *frmlabel;  Comprehensive position and dialog box width and length Qlabel *frmvaluelabel;   Qlabel *poslabel;  Position coordinates are x, y Qlabel *posvaluelabel;   Qlabel *geolabel;  X, Y and the dialog box does not contain the size of the caption, the length width Qlabel *geovaluelabel;   Qlabel *widthlabel;  Inside the wide Qlabel *widthvaluelabel;      Qlabel *heightlabel;  Inside the long Qlabel *heightvaluelabel;      Qlabel *rectlabel;  The beginning of the 0,0 and the inside of the long and wide Qlabel *rectvaluelabel;        Qlabel *sizelabel;  Inside of the long-width Qlabel *sizevaluelabel;    Qgridlayout *mainlayout;     Grid Layout protected:void moveevent (qmoveevent *); When the dialog moves, the coordinates change. void Resizeevent (Qresizeevent *); dialog box size change words}; #endif//Geometry_h


Geometry.cpp

/*** Book: "QT5 Development and examples" * Function: Display the coordinate information of the dialog box, parameter information * file: geometry.cpp* time: January 20, 2015 20:19:35* Author: cutter_point*/#include " Geometry.h "Geometry::geometry (qwidget *parent)//constructor: Qdialog (parent) {Setwindowtitle (tr (" Cutter_point geometry "))  ;    Xlabel = new Qlabel (tr ("X ():"));  Coordinates x Xvaluelabel =new Qlabel;  Ylabel =new Qlabel (tr ("Y ():"));  Yvaluelabel =new Qlabel;  Frmlabel =new Qlabel (tr ("Frame:"));  Frmvaluelabel =new Qlabel;  Poslabel =new Qlabel (tr ("POS ():"));  Posvaluelabel =new Qlabel;  Geolabel =new Qlabel (tr ("Geometry ():"));  Geovaluelabel =new Qlabel;  Widthlabel =new Qlabel (tr ("width ():"));  Widthvaluelabel =new Qlabel;  Heightlabel =new Qlabel (tr ("Height ():"));  Heightvaluelabel =new Qlabel;  Rectlabel =new Qlabel (tr ("Rect ():"));  Rectvaluelabel =new Qlabel;  Sizelabel =new Qlabel (tr ("Size ():"));  Sizevaluelabel =new Qlabel;   Mainlayout = new Qgridlayout (this);  Grid Layout Mainlayout->addwidget (xlabel, 0, 0);  Mainlayout->addwidget (xvaluelabel,0,1); Mainlayout->addwidget (Ylabel,1,0);  Mainlayout->addwidget (yvaluelabel,1,1);  Mainlayout->addwidget (poslabel,2,0);  Mainlayout->addwidget (posvaluelabel,2,1);  Mainlayout->addwidget (frmlabel,3,0);  Mainlayout->addwidget (frmvaluelabel,3,1);  Mainlayout->addwidget (geolabel,4,0);  Mainlayout->addwidget (geovaluelabel,4,1);  Mainlayout->addwidget (widthlabel,5,0);  Mainlayout->addwidget (widthvaluelabel,5,1);  Mainlayout->addwidget (heightlabel,6,0);  Mainlayout->addwidget (heightvaluelabel,6,1);  Mainlayout->addwidget (rectlabel,7,0);  Mainlayout->addwidget (rectvaluelabel,7,1);  Mainlayout->addwidget (sizelabel,8,0);  Mainlayout->addwidget (sizevaluelabel,8,1); Updatelabel ();}   Update coordinates void Geometry::updatelabel () {QString xStr;  Gets the result of the X () function and displays Xvaluelabel->settext (Xstr.setnum (x ()));   QString Ystr;  Get the result of the Y () function and show Yvaluelabel->settext (Ystr.setnum (Y ()));   QString Framestr;  Obtain the results of the Framegeometry function and show QString tempStr1, TEMPSTR2, TEMPSTR3, TEMPSTR4; Framestr = tempstr1.seTnum (Framegeometry (). x ()) + "," + Tempstr2.setnum (Framegeometry (). Y ()) + "," + Tempstr3.setnum (Fram  Egeometry (). Width ()) + "," + Tempstr4.setnum (framegeometry (). height ());  Frmvaluelabel->settext (FRAMESTR);    QString Positionstr;  Obtain the result of POS function and display QString tempStr11, tempStr12;  Positionstr = Tempstr11.setnum (pos (). x ()) + "," + Tempstr12.setnum (POS (). Y ());  Posvaluelabel->settext (POSITIONSTR);   QString Geostr;  Get the results of the geometry () function and show QString tempStr21, TempStr22, TempStr23, TempStr24; Geostr = Tempstr21.setnum (Geometry (). x ()) + "," + tempstr22.setnum (geometry (). Y ()) + "," + tempstr23.se  Tnum (Geometry (). Width ()) + "," + tempstr24.setnum (geometry (). height ());  Geovaluelabel->settext (GEOSTR);   QString Wstr, Hstr;  The result of the width, height function is obtained and the Widthvaluelabel->settext (Wstr.setnum (width)) is displayed.  Heightvaluelabel->settext (Hstr.setnum (height ()));    QString Rectstr; Get the result of the RECT function and show QString tempStr31, TempStr32, TempStr33, TempStr34; Rectstr = Tempstr31.setnum (Rect (). x ()) + "," + tempstr32.setnum (Rect (). Y ()) + "," + Tempstr33.setnum (r  ECT (). Width ()) + "," + tempstr34.setnum (Rect (). height ());  Rectvaluelabel->settext (RECTSTR);    QString Sizestr;  Get the result of the size function and show QString tempStr41, TempStr42;  SIZESTR = tempstr41.setnum (Size (). Width ()) + "," + tempstr42.setnum (Size (). height ()); Sizevaluelabel->settext (SIZESTR);} Redefine Move dialog box event void Geometry::moveevent (Qmoveevent *) {Updatelabel ();} void Geometry::resizeevent (Qresizeevent *) {Updatelabel ();} Geometry::~geometry () {}


Main.cpp

#include "Geometry.h" #include <qapplication>int main (int argc, char *argv[]) {  qapplication A (argc, argv);  Geometry W;  W.show ();  return a.exec ();}

Run results





Well, I found that more than 1M photos can not be uploaded, 666666, I remember it seems to be 2M, blame me too naïve???







"QT5 Development and examples" 17, a dialog box coordinates the parameter display

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.