PDA

View Full Version : Adding QTCheckBox Manually



QTNovice
6th September 2013, 00:10
I have primarily always used QTCreator to build the GUI for my QT projects. I want to add a QCheckBox manually but I'm not sure how to go about it. I went into my ui_mainwindow header and added a new QCheckBox object while calling setObjectName, setObjectGeometry, raise(), etc., as the generated files do for all my other GUI objects, but nothing was visible. I am reading something about a QCheckBox needing to be put into a QTableWidget or something along those lines? How can I program this into my auto generated UI header file without having to resort to QTCreator?

ChrisW67
6th September 2013, 04:20
You cannot put it in the auto-generated UI code because, well, that code is automatically generated and will be overwritten if the *.ui file is changed.

You can either:

build the entire UI in code in your class constructor (like the majority if the Qt examples), or
allow the Designer UI to initialise (i.e. setupUi(this)) and then create a QCheckBox object and insert it into a layout that the generated UI contains.

QTNovice
6th September 2013, 06:51
You cannot put it in the auto-generated UI code because, well, that code is automatically generated and will be overwritten if the *.ui file is changed.

You can either:

build the entire UI in code in your class constructor (like the majority if the Qt examples), or
allow the Designer UI to initialise (i.e. setupUi(this)) and then create a QCheckBox object and insert it into a layout that the generated UI contains.


I think you misunderstand. My .ui file is long gone for this project, so my only option is to add it manually. I need to know how to add a QCheckBox manually with nothing more than the auto generated header files I was originally given through QTCreator. I would normally add it through QTCreator but my .ui file is gone, as I said, so I need to add it manually.

Rajesh.Rathod
6th September 2013, 07:02
If you have Qt Designer installed on your machine then open designer create one frame or main window and add QCheckBox on it.
Now go to menu and select Form > View Code...
this will show you code for your current ui file from which you can get idea how to add QCheckBox programmatically.

anda_skoa
6th September 2013, 08:55
added a new QCheckBox object while calling setObjectName, setObjectGeometry, raise(), etc., as the generated files do for all my other GUI objects, but nothing was visible

Did you add it to the layout?



I would normally add it through QTCreator but my .ui file is gone, as I said, so I need to add it manually.


It might be better to invest a couple of minutes and recontruct the UI file instead.

How did you end up in this situation? Added the generated file to you version control system instead of the UI file?

Cheers,
_

QTNovice
7th September 2013, 15:37
I ended up in the situation simply because the project I am working on is very old and I saved the project but lost the UI file when I reformatted.

I figured it all out though, so thanks for the help.