-
Apr 4, 2013
Converting a QFrame to a QWidget
I had spent the better part of yesterday building, integrating, and testing a Qt form that was a single panel on a larger display. This morning I was tasked to “make it a popup” instead.
The back-end to the GUI was a C++ class that inherited a custom
SubFrameobject, which inherits Qt’sQFrameobject. My company also has a customPopupclass. Very similar toSubFrame, thePopupclass, notably, inherits instead from aQWidget.I made the appropriate edits to my source code so that
MyFormThinginheritedPopupinstead ofSubFrame. It didn’t build, though. ThesetupUi()method in the Qt-generated Ui file expected aQFrame *input parameter, but fromMyFormThingI was passingthisto the method—thisnow being aQWidget *. My GUI, as far as the .ui file went, was still aQFrame. It needed to be aQWidget.Simply casting the
QWidgetto aQFramewon’t work, since aQWidgetis a not aQFrame. This:ui->setupUi(dynamic_cast<QFrame *>(this));
will build, but it will not run very far—the messed up dynamic cast throws an exception and a core dump is born.
I knew I needed to change the .ui file, somehow, to make my
QFrameaQWidget. Qt Creator doesn’t, AFAIK, give the ability to do this kind of morph—at least not in version 1.3.1, which is what’s installed on our lab computers. And obviously I wasn’t going to rebuild the whole thing from scratch starting with aQWidgetbase. Some quick Googling led me here.The .ui files in Qt are just XML. Near the top of the
MyFormThing.uifile, I found this:<widget class="QFrame" name="MyFormThing">
<property name="frameShape"> <enum>QFrame::WinPanel</enum> </property><property name="frameShadow"> <enum>QFrame::Raised</enum> </property>
So I changed
class="QFrame"toclass="QWidget", deleted the frame-specific properties, and rebuilt/ran without issue. When I inspected the GUI element in Qt Creator’s Form Designer, it said it was aQWidget, so it looks like that worked.tl;dr Change a
QFrameinto aQWidgetby directly editing the XML in the .ui files. -
Apr 3, 2013
This Site Needs Infinitely More GIFs
Today I set up this website. This blog section here was a Wordpress install–v straightforward. The rest of the site, which I haven’t thought much about yet, is currently just the HTML5 Boilerplate template.
I also set up a Git repository and a locally hosted copy of the site (MAMP ilu). I haven’t used Git that much, but the commands are similar to SVN. Also spent some time live-chatting the hosting company’s tech support to set up SSH access to the server.
Eventually, this blog will be a place where I can talk about CS and programming-related things. While I’m here, let’s see how code looks with this theme:
git initprintf("Hello cruel world\n");I have a vague sense that the landing page of my site will just be a glorified ‘About’ page with a bunch of links to different hosted projects. I like having this lil website. Hi.
-
Apr 3, 2013
First Post
Hello. Eventually there will be some content here. Thanks for visiting :)
- 15
- 16
- •