Quick Tip: QProgressBar as a Busy Indicator

This is a super simple tip that doesn’t really have much to it. A busy indicator is just a visual cue to show the user that something is happening. To use a progress bar in Qt as one, you just need to set the minimum and maximum values to 0. If you do this, you get an infinite progress indicator. This is a better alternative to a progress bar when you have a process in which you cannot calculate the percentage completed, or one that takes a really long, undetermined, amount of time. An example with the Fusion style (that I use for basically any QWidgets these days) yields an animated diagonal stitch pattern:

Busy Progress Bar

The Qt Fusion style progress bar.

On Windows 7, you get a nice animated effect as well, but with a smaller colored area moving from left to right infinitely.

Windows 7 Busy Progress Bar

The Windows 7 version of the busy progress bar indicator

I hope the tip helped you out! Happy coding!

Run As Admin Utility Application

Recently, I wrote a small, win32 native utility to launch executables with administrator rights by utilizing a UAC prompt when launching the other application. You can check out the full source on Github if you want to learn more. The application can also utilize configurable and dynamic command line arguments, if your application needs that.

The release binary is around 30KB in size, and produces no pop-up windows unless there is an error. Errors are handled pretty well and displayed using a discrete message box. Feel free to redistribute it with your application, and attribution would be nice (just leave the executable name intact πŸ˜‰ ).

Also, if you could, comment or let me know if you are using it. I’d love to get any feedback you have on it, or you can use the Github issue system for bugs/feature requests. A friend of mine has already told me he will be using this for his Python application, since he cannot find a better way to launch his application with administrator rights by default.

Check back often to see if I add new builds that support more features! Happy coding!

You can find the latest releases on Github here

Quick Tip: Copy a QPixmap to the System Clipboard in Qt

A few days ago, we went over copying any amount of text to the system clipboard using the system clipboard. However, you can also leverage the full-power of this by copying images and pixmaps to the system clipboard. Let’s get started!

Example UI with Pixmap

Our example UI for this. Simply set a pixmap on a label. along with a button.

Behold my stunning UI for this example. πŸ˜› Now that you have your GUI setup, go to the push button’s slot (or wherever you want to put the code) and you are left with this:

    QClipboard *p_Clipboard = QApplication::clipboard();
    p_Clipboard->setPixmap(*(ui->label->pixmap()));

This is essentially what we did with text, however, with a different method. Note the dereference of the constant pointer we get to the label’s pixmap. This is essential, because the setPixmap() function wants a QPixmap object (taken by reference, not pointer). How can you not love C++? πŸ™‚

Then you can paste it anywhere that lets you insert images through the paste!

The image pasted in MS Word

Here’s the copied pixmap pasted into Word. You can also paste it elsewhere, as long as the form accepts images from the clipboard.

And that about wraps it up. I hope you can use this in one of your projects, and share it if it was useful. Happy coding!

Quick Tip: Copy Any Text to the System Clipboard in Qt

Now, this is a super quick tip, as it’s really a no-brainer. The explanation (if you need one) is that a QApplication has a global instance of the clipboard, which can be accessed by simply getting a pointer to it. So lets just get to the code!

    QClipboard *p_Clipboard = QApplication::clipboard();
    p_Clipboard->setText(textForClipboard);

And viola! Just like that, your text should now be on the system clipboard. Happy coding!

Get some color back in Visual Studio 2012 icons!

If you are still using Visual Studio 2010 (or older?), then you can just ignore this. Apparently, Microsoft’s UI design team decided to change the icons to a more “monochrome” color palette in VS 2012, so what you get is essentially gray icons for everything. These icons are a far cry from what we have come to know as save, open file, open folder, etc. However, I personally don’t really care to be honest, unlike most developers. If you seriously use Visual Studio 2012, then there is no reason you shouldn’t do these two things:

  • Learn those shortcuts! This is a must. Visual Studio has so many shortcuts that most actions take two keys plus a modifier! It sure beats having to look through context menus that are so big, they fill up more than 1,080 pixels vertically…
  • Customize the layout where everything is somewhere you can find immediately. Re-arrange the toolbars and memorize the icons’ respective locations. Even if you know all the shortcuts (unlikely), there are still some things I prefer doing with the mouse–namely opening files, as it’s easier to use the mouse to browse through the files.

If this still isn’t enough, there is always the NiceVS Visual Studio extension, which appears to bring back the colored icons so many people have come to miss so much. Use at your own risk, however, as I didn’t even bother to test this plugin. If Microsoft’s made a UI decision that coincides with the Metro UI (which everyone also seems to hate), it isn’t going away easily. There’s no sense in installing a plugin to try and undo what Microsoft has done, in my opinion.

Qt Creator 2.8.0 is finally here!

At long last, we have the release version of Qt Creator 2.8.0! I can’t wait to fill up all my monitors with multiple Qt Creator windows, and refactor C++ like C# (okay, maybe not that good… yet). If I’d have to ask for a feature improvement though, it’d be speeding up the autocompletion. Visual Studio is still way ahead in terms of that, however, Qt Creator is free and open-source, so I am not complaining. πŸ˜‰

You can read the Digia write-up over on their Qt blog for all the finer details.

MultiEditing Visual Studio Extension

Lately, I’ve been using Sublime Text for some lighter jobs where Visual Studio/Qt Creator just isn’t needed. I have really been loving Sublime Text’s multi-cursor feature. I can’t believe every IDE doesn’t have this! The feature is really, really handy for a lot of cases. However, I stumbled upon this handy Visual Studio plugin that emulates multiple cursors where Visual Studio does not!

It’s free, so I encourage you to pick it up today. I didn’t notice any slowdown from using the plugin, but that’s going to be minute if you have a machine capable of running Visual Studio 2012 with a whole bunch of other extensions + a giant solution (that you have been meaning to organize…). The only thing I could complain about–if I’m allowed to complain since it’s free and I love it so much–would be that some shortcuts that I use in the text editor don’t seem to work across multiple cursors. For me, this is namely the CTRL and SHIFT keys for movement and selection.

You can find the extension on theΒ Visual Studio Extension Gallery website here. The extension worked in C# and C++, and it appears to support other languages as well.

Let me know if there are any other great VS extensions I should check out sometime! I’d also like to hear if you think Visual Studio should include this feature in an upcoming release, because I sure think it would add a great productivity enhancement for editing code.