To determine device is tablet or mobile, I use criteria: if device's screen diagonal is greater than 7 iches, the device is tablet. To get diagonal, I use:
QScreen *srn = qApp->screens().at(0);
QSizeF physicalSize = srn->physicalSize();
But when I use Nexus 4
, which has 4.7 inches, physicalSize
returns greater than 7 inches.
I don't really know, whether the device implementers did error, or Qt framework. Anyway, another applications obtained from playmarket
determines the matter correctly. QUESTON: What is the best way to determine, tablet or mobile the device is?
I don't really know what you want to do but if you only want two different layout files for phone and tablet then you can do this: When you work with Fragments you usually have two different layoutfiles. One just contains a Framelayout, which is for the mobile devices and one that hold two Framelayouts for the tablet devies.
A good way to determine if the device is a phone or a tablet, is to create a
refs.xml
file in your values folder. Just put an item with a name in it and the layout you want to refer to. This file is for the mobile device:Than you reate another values folder named values-sw600dp. In this folder you crate another
refs.xml
file. Its IMPORTANT to give the same item name for both refs files. Then you refer on your tablet layout.Now you can get set the content view with your item name and android will just pick the right one if you have a tablet or a phone.
In your onCreate() method in your activity:
Now you must check if your Framecontainer of the tablet view is null: