The effect I wanted to achieve is something like the Mail icon in iPhone. There is a rounded rectangle on the topright corner of the Mail icon. The number inside the rectangle shows the current number of unread emails and can be dynamically changed when new emails come in. I am wondering if it is possible to do this using Qt 4.6 for a desktop application interface. If it is possible, what classes should I start to learn? (I guess Qt should have some bitmap manipulation class.) Thank you.
You can draw into a QImage or QPixmap using QPianter, then save the icon to a png file - or since you are using it in your app, just change the internal icon directly.
Take a look at QImage and QPainter.
Related
I have a small problem whit QScrollbar.
for example,
This is a one my project in C#
At left panel, the user loads a graphic image and can pick elements.
but I see in Qt don't exist Split Panel whit automatic Scrollbar.
I tried to use QScrollArea, but if user maximizes Window it's a problem.
anyone have a solution or a good way to make this in qt?
I have a main window with some internal dockable windows. I can move, resize and redock those dockable windows. After close and reopen the program, I want the moves, sizes and redocking are kept. Any easy way to implement it? I think it will use settings. But which info should be saved in settings. And how to set a default layout of all these dock windows? When click an action button, it can be restored. Thanks.
Check out QMainWindow::saveState/restoreState. It does exactly this.
To Save:
QSettings settings;
settings.setValue("DOCK_LOCATIONS",this->saveState(SOME_VERSION_DEFINE));
To Restore:
QSettings settings;
this->restoreState(settings.value("DOCK_LOCATIONS").toByteArray(),SOME_VERSION_DEFINE);
Unfortunately, no, there is no built-in way to do this.
You'll need to loop through all your toolbars and dockable widgets and write their positions (and possibly their visibility) to a file. To restore, you can read that file and set your positions based on what you read.
The good news is that once you have such a system set up, making a default layout is easy - move all your widgets where you want them, then save your layout file, just like you do the user layouts above. You can even have multiple layouts, as long as they all get separate files.
I'm trying to create a plugin using QT that is able to open a webpage, yet I only want the window to be focused on a 300x300 pixel area. The area is somewhere in the middle of a page.
I was able to load the page and then perform a scrolling operation, but that doesn't seem very clean.
Does anyone know if this is possible? I checked the QtWebFrame class reference:
http://doc.qt.io/archives/qt-4.7/qwebframe.html
but maybe I'm missing something. Thanks in advance!
If you don't need interaction with the page, you could call QWebFrame::render(QPainter* painter, const QRegion& clip) and draw it onto a widget, specifying clip to be the required area.
I'm trying to get a fullscreen dialog to launch after clicking a button in my MainWindow using QT on Mac. I use showFullScreen() to display the dialog, and the whole screen does get taken up. The problem is that the widgets within the dialog are still constrained to the 1024px geometry set for the dialog in the designer, and positioned in the upper left corner of the screen. I can manually change the geometry in the ui file to match my desktop, but I can't get it to work programmatically. I have tried setting the geometry of the dialog to desktop()->geometry() and the running updateGeometry() and that did not work. I tried it both before and after running the showFullScreen() function.
I've tried setting the sizePolicy of the dialog to Expandable, Maximum, Preferred, and just about every other setting, and still no go. Right now it is an absolute bare bones project, show the only code to show would be the sessionscreen.showFullScreen() function in the button_clicked() slot.
I'm sure there is something I'm missing, but I have been at it for hours, scouring Google and Qt help forums and coming up empty. Hopefully someone can point out something very simple that I am missing.
Nevermind, I am indeed using layouts wrong, because the widgets don't move if i resize the layout in designer either. I thought I followed the tutorial videos exactly. This is why I prefer text based tutorials. Oh well, back to Youtube I go.
I've written a small Processing App which I'm planning to release soon. What's still missing is a sweet custom icon for Titlebar/Taskbar (Win) and Dock (Mac). Any suggestions how to do this?
Thx!
Meanwhile I figured it out on my own:
Obviously this works for Mac OS by replacing the sketch.icns file within the exported app, for win & liunx is done by adding this line to your setup method:
frame.setIconImage( getToolkit().getImage("sketch.ico") );
It depends if you have any artistic ability or not.
If not, then you can hire an icon designer to do one, or search the web for free icons - there are billions.
If you have a modicum of artisticness, then you could grab a free icon that is almost what you want and then tweak it. IcoFX is a great free application for doing this sort of thing.
If you think you have what it takes to draw an icon from scratch, then a good plan is to use a vector art package. This allows you to export the same graphic at multiple resolutions so you can get top quality at every icons size you need (from 16x16 to 256x256). Alternatively, draw a large (512x512) verison in a bitmap editor and then downscale it as required. As long as you start big and downscale, you shouldn't have any problems (although to get a good icon at 16x16 and 32x32 you will still need a good eye and a lot of manual tweaking).
In your code, just type this line:
frame.setIconImage( getToolkit().getImage("sketch.ico") );
For Windows/Linux, this will do it. For Mac/OSX, follow these steps:
Find your sketch in Finder
Right click > info, or CmdI
Find your icon and open it in Preview
In Preview, click on your icon and press CmdA or right click > select all
In Preview, press CmdC, or right click > copy
Go back to Finder. Click on the current icon of your sketch. You'll know you've selected it when a blue outline appears. Press CmdV, or right click > paste
Tips:
The standard icon size is 512x512
When making your icon, make sure that your transparencies are working