This is just a dump of the notes I took for this Qt Video:
2009/03/04 video, More Native Look & Feel
* http://qt.nokia.com/developer/learning/online/talks/developerdays2009/tech-talks/how-to-make-your-qt-application-look-native
* Intro, Styles, Style Sheets, Dialogs, Cross platform tips, Native platform tips
* More tips at labs.trolltech.com
The 4 UI guidelines:
* Windows User Experience Interaction Guidelines
* Apple HIG
* KDE UIG
* GNOME HIG
Feel aspects:
* GNOME has (Cancel, OK)
* Windows has (OK, Cancel)
Use Styles:
* style()->drawPrimitive(QStyle:PE_IndicatorBranch, &opt, painter, this);
* QProxyStyle, such as for (Windows Vista) vs. (KDE Oxygen), example:
class MyProxyStyle : public QProxyStyle {
int styleHint(StyleHint hint, …) const {
if( hint == QSTyle::SH_UnderlineShortcut )
return 0;
return QProxyStyle::styleHint(hint, …);
}
Style Sheets:
* careful – they can break look and feel
* try to blend with system palette
QString css = "QLabel{ color:palette(highlight); }";
* if you need custom colors
QColor color(255, 0, 0);
QString css = QString("QLabel { color:%1;}").arg(color.name())
Dialogs, QDialogButtonBox
* manages button order, layout, icon, text
QDialogButtonBox box(QDialogButtonBox::Save | QDialogButtonBox::Discard | QDialogButtonBox::Cancel);
* can use custom buttons as well
QDialogButtonBox box;
box.addButon(myCustomButton, QDialogButtonBox::AcceptRole);
Dialogs, QFormLayout
* such as for config dialogs
* Mac labels aligned right, Windows labels aligned left
* manages label alignment
* row wrapping (on embedded devices, it will split the lines)
* implicit buddy assignment
Dialogs, Dialog modality
* he said they are against the user guidelines
* on Snow Leopard (Mac OS X 10.6), they don’t ask you to confirm changes
* Mac apps tend to be a single doc interface
* QDialog methods – use open(), so that on mac os x it will be a sheet
QDialog::exec() // modal
QDialog::show() // non modal
QDialog::open() // window modal
if(!messagebox) {
messagebox = new QMessageBox(…);
connect(messagebox, SIGNAL(finished()), this, SLOT(dialogClose(int));
}
messagebox.open()
* if we want a dialog attached to a specific window, use QDialog::open()
* a window is not a sheet, if it’s covering other windows
Cross platform tips, when showing file location in title bar
* Do this:
setWindowModified(true);
setWindowFilePath("untitled.txt");
* because
Windows uses a *
Mac puts a small dot in the close circle button X
differences in path in title bar
Cross platform tips, ask for attention
* QApplication::alert(widget, msec = 0);
* makes the windows taskbar flash / mac dock bounce
Cross platform tips, QDesktopServices
* storageLocation(), gives access to default directories, documents, temp, music
* openUrl(), launches URL in default system application
* QUrl from PDF file will open with default app
* openUrl("mailto:myself@gmail.com")
* openUrl("http://qt.nokia.com")
* openUrl(QUrl::fromLocalFile(…))
Cross platform tips, shortcuts
* Qt has QAction::setShortcut() and QAction::setShortcuts(); use setShortcuts()
* QKeySequence::keyBindings(QKeySequence::NextChild)
Use this to check for shortcut key conflicts
Test it on all platforms
Cross platform tips, icons
* on windows you’re not supposed to use icons for anything anyway? what?
* use consistent icon theme (not random conglamoration of icons)
such as Oxygen (KDE 4), or Tango (free project, sort of GNOME related?)
* QIcon::fromTheme("documents-edit");
QIcon::fromTheme("documents-edit", QIcon("document.png"));
new in Qt 4.6
lets you load an icon from an icon theme
this is great for KDE and GNOME
for Windows and Mac, bundle icon theme as a resource
for KDE, the idea is to use KIcon
test changing the theme on (such as on GNOME / KDE etc)
* QAction::setIconVisibleInMenu(bool)
QApplication::Attribute(Qt::AA_DontShowIconsInMenu)
Mac default is false
But next version of GTK for GNOME is disabling these – so I should leave it alone
Windows – he thinks people overuse icons, so I could set it to false, specifically for Windows
Cross platform tips, QAction Priority
* new Qt 4.6
* QAction::setPriority(QAction::Priority)
* allows Qt to collapse layouts intelligently (such as shrink icons, remove icon text, etc)
* decides, for which icons, the label is collapsed
* they plan to add more support for this in the future
Cross platform tips, MDI interfaces
* multiple document interfaces
* don’t use them (for example, use tabbed views instead)
* Mac doesn’t support, GTK+ doesn’t support, Microsoft discourages it (says use MDI)
Native platform tips, use native code
* ifdefs: Q_WS_WIN, W_WS_MAC, Q_WS_X11
* QWidget::winid(), gives window handle (HWND, NSVIEW, X handle)
Native platform tips, Mac MainWindow Demo
* Qt’s main window demo is not very good?
* 29 min 50 sec:
it’s almost impossible to use the same layout on the mac and say with it straight face that it "looks native"
Mac tends to require modifications to your interface if you truly want it to look native
Native platform tips, Mac icons
* blowing up a 32×32 icon looks terrible
he said to use a gray icon for tray – but that’s no longer true?
Native platform tips, Mac QMenuBar
* create a QMenuBar without a parent
* first menu bar created will be the default menu bar
* "Qt Creator doesn’t do this, but it should – we’ll fix that"; is it already fixed?
Native platform tips, Mac unified tool bar
* QMainWindow::setUnifiedTitleAndToolBarOnMac()
* do enable it, but you may have to test / tweak it
* he said he hopes next version of Qt will handle the default better?
* you don’t have room for more than 10 Mac icons
Native platform tips, Mac custom doc menu (sp, dock?)
* QMenu *menu = new QMenu;
// Add actions to the menu
extern void qt_mac_set_dock_menu(QMenu *);
qt_mac_set_dock_menu(menu);
Native platform tips, Mac menu placement
* Qt automatically rearranges menu entries
based on name: about, settings, preferences, quit, exit
just use the name to call it "settings" etc, and it will go to Application::preferences on Mac
* override with QAction::menuRole, AboutRole, PreferencesRole, NoRole (means don’t move)
Native platform tips, X11
* Qt 4.6 has KDE improvements
* see freedesktop.org, ?
* make a .desktop file
handles application icon, menu entry, mimetype
* use standard icons
* test on both GNOME and KDE (and possibly others, such as XFCE)
different themes, shortcuts, window behavior
* use DESKTOP_SESSION environment variable, returns GNOME or KDE or XFCE
if we want to do different things for GNOME vs. KDE etc?
Native platform tips, Windows registry via QSettings
* QSettings reads the Windows registry, by default
QSettings settings("HKEY_CURRENT_USER\\ …", QSettings::NativeFormat);
bool result = settings.value("EnableBalloonTips", true).toBool();
Native platform tips, Windows QCommandLinkButton
* introduced with Windows Vista, but works just as well on other platforms (Windows 95, Mac, X11)
* great for wizards: instead of having the user do (click radio button, then click next),
instead just do (click your choice – click just once)
Native platform tips, Windows explorer style look and feel
* Windows native – this guy says it’s lost some of it’s meaning
he says apps tend to only use the look and feel for certain parts of the GUI
* http://labs.trolltech.com/blogs/2007/06/08/explorer-style-toolbars/
* QtDotNetStyle, Office 2003 style – although it’s going out of fashion
Native platform tips, Windows enable blur behind (Windows Vista, Windows 7)
* not supported in Qt as of 4.6
* but you can use the native Windows API, if you set
WA_TranslucentBackground and WA_NoSystemBackground, on the widget
* he wrote an example enable blur function, EnableBlur() (sp?)
—
Screen Shots:
OK and Cancel Buttons

QDialogButtonBox

QFormLayout

Icons

Pem (Admin) :: 2010/04/13 (Tuesday, April 13, 2010) ::
Qt ::
No Comments »