How to set the maxlength of a Label in PyQt4?
self.ui.labelxyz.maxlength(15)
Isn't the correct command for this.
Kind regards;
you can check maximum length with self.ui.labelxyz.maximumWidth() or set it like this: self.ui.labelxyz.setMaximumWidth(15)
maximumWidth : int
This property holds the widget's maximum width in
pixels. This property corresponds to the width held by the maximumSize
property. By default, this property contains a value of 16777215.
Access functions: int maximumWidth () const
void setMaximumWidth ( int
maxw )
Related
I was trying to set the BackColor of my form in C++, and I a syntax error, to do with the 'FromArgb' statement, when using the code:
this->BackColor = gcnew Color::FromArgb(0,0,15);
What should I do?
You haven't given us enough context to answer, but I'll hazard a guess that FromArgb is a function, not a type, in which case it doesn't make sense to new (or gcnew) it.
If that's the case, and assuming BackColor is a Color object and not a pointer, and that FromArgb returns a Color by value, then you want
this->BackColor = Color::FromArgb(0,0,15);
If that doesn't work, please let us know exactly what BackColor and FromArgb are.
Color is a public value class Color - hence gcnew is wrong.
Also the number of arguments do not match:
public: static Color FromArgb(
unsigned char a,
unsigned char r,
unsigned char g,
unsigned char b)
I want to make UI for tablet like shown in images.This UI will repeat according to number of items. And the position of each block (i.e small or big block) can change dynamically. Please give me suggestion which view,layout i should use.
Any suggestion would be appreciated...thanks in advance.
If you are targeting a API v14 or above, you can use GridLayout: http://developer.android.com/reference/android/widget/GridLayout.html
Using LinearLayout where each category is added and using RelativeLayout for each category is a good option. You should customize onlayout method of the relative layout as a function of number of products it contains.
You can use fragments, listview as well.
EDIT after image change: You can just extend relativelayout and override onLayout method. This will perform better than nested layouts and I can't think of anything else you can get away with less effort.
EDIT for elaboration:
Here is an example class I use. Basically in the onlayout method you make every decision and tell all the child views to lay them in a rectangle by calling layout method of each of them and passing the parameters of the rectangle. See how I use layout method of child view to dictate the rectangle.
public class KnockPile extends HandPile
{
private static final String TAG = "KnockPile";
static final int EXPECTED_CARDS = 3;
int mColoring; // this is the coloring group this pile is associated with.
// every card added to this pile should be set with this color.
public KnockPile(Context context, GameActivity ref , int ingroup)
{
super(context );
mColoring = ingroup;
mActivityReference = ref;
setWillNotDraw(false);
setClickable(true);
setOnDragListener(this);
mCardBorders = new ArrayList<Integer>();
final LayoutTransition transition = new LayoutTransition();
setLayoutTransition(transition );
//transition .enableTransitionType(LayoutTransition.CHANGING);
//transition .disableTransitionType(LayoutTransition.CHANGE_APPEARING);
}
/**
* this overrides the card ordering of handpile. This method lays the cards in a linear fashion.
* Possibly overlapping fashion. This is not dependent to orientation of screen.
*
* #see com.kavhe.kondi.gin.layouts.HandPile#onLayout(boolean, int, int, int, int)
*/
#Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int availablewidth = getMeasuredWidth() ;//this is the maximum availlable
int distance = availablewidth /Math.max(getChildCount(), 1) ; // the horizontal distance between two cards
Log.v(TAG,"available width onlayout is :" + availablewidth +"and distance is " + distance);
int cardheight = getHeight();
int cardwidth = cardheight*3/4;
if(distance > cardwidth) distance = cardwidth;
mCardBorders.clear();
for(int i = 0 ; i < mCards.size() ; i++)
{
//save this border into a global variable so that it can be used when one of the cards dragged
//by user to show that user can insert to that location
mCardBorders.add( i*distance);
mCards.get(i).layout( i*distance , 0 , cardwidth+ i*distance , cardheight);
}
}
}
and this is from documentation
protected void onLayout (boolean changed, int left, int top, int right, int bottom)
Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.
Parameters
changed This is a new size or position for this view
left Left position, relative to parent
top Top position, relative to parent
right Right position, relative to parent
bottom Bottom position, relative to parent
It is also possible through table layout with its row span property
Are the "products" always going to fit nicely on lines as you have drawn? If then, you can use LinearLayouts (Vertical and Horizontal) nested in each other.
To design such UIs for Tablets you should use Fragments and inside the fragment add/remove your respective layouts. If you are taking Relative Layouts then proper usage of RelativeLayout.LayoutParams is required.
If you are looking for a best example which uses Fragments try Google IO app source. It uses various dynamic UI features.
Hope it helps !
With the help of StaggeredGridView I sloved my requirement.
Thanks to all for help and support.
I'm working on an MFC project which was transferred to me.
It's basic layout (main frame derived from CFrameWnd) is shown in this sketch:
The CommandBar and the ControlBar, both derived from CDialogBar, were created using WS_CHILD | CBRS_ALIGN_RIGHT as style.
This is fine for the alignment. But I would like to define the widths of these two elements and cannot find a way to set it.
When I tried to EnableDocking for the dialog bars, I couldn't manage to resolve the assertions. Also I'm not sure if this is what I am looking for.
Overriding CalcDynamicLayout and returning the calculated size is what I was looking for.
Example:
CSize CommandBar::CalcDynamicLayout(int nLength, DWORD dwMode)
{
CSize size;
CRect parentRect;
if (GetParent())
GetParent()->GetClientRect(&parentRect);
size.cy = parentRect.Height();
size.cx = (int)(abs(parentRect.Width() - parentRect.Height() + GetSystemMetrics(SM_CYMENUSIZE)) * 0.5);
return size;
}
I've got a problem with the CGBitmapcontext.
I get en error while creating the CGBitmapContext with the message "invalid Handle".
Here is my code:
var previewContext = new CGBitmapContext(null, (int)ExportedImage.Size.Width, (int)ExportedImage.Size.Height, 8, (int)ExportedImage.Size.Height * 4, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedFirst);
Thank you;
That is because you are passing null to the first parameter. The CGBitmapContext is for drawing directly into a memory buffer. The first parameter in all the overloads of the constructor is (Apple docs):
data
A pointer to the destination in memory where the drawing is to be rendered. The size of this memory block should be at least
(bytesPerRow*height) bytes.
In MonoTouch, we get two overloads that accept a byte[] for convenience. So you should use it like this:
int bytesPerRow = (int)ExportedImage.Size.Width * 4; // note that bytes per row should
//be based on width, not height.
byte[] ctxBuffer = new byte[bytesPerRow * (int)ExportedImage.Size.Height];
var previewContext =
new CGBitmapContext(ctxBuffer, (int)ExportedImage.Size.Width,
(int)ExportedImage.Size.Height, 8, bytesPerRow, colorSpace, bitmapFlags);
This can also happen if the width or height parameters passed into the method have a value of 0.
i wanted to know if i can draw a text in Cimg graphic library draw_text function and change the font of the text to another font ?
You can't load own fonts in CImg, but you can see example https://github.com/tttzof351/CImgAndFreetype for load custom fonts using freetype and render text on bitmap using cimg.
No. CImg's text drawing is very simplistic.
CImg<T>& draw_text(const int x0, const int y0,
const char *const text,
const int, const tc *const background_color,
const float opacity, const CImgList<t>& font, ...)
font is just a CImgList of letters (i.e. font[letter-'a'] is an image of "letter"). Either make your own or use one of the built-in options:
static const CImgList<T>& font(const unsigned int font_height,
const bool variable_size=true);
or
static CImgList<T> _font(const unsigned int *const font,
const unsigned int w, const unsigned int h,
const bool variable_size)
where font here is one of the predefined fonts at the top of CImg.h such as font12x24.
Assuming you mean this Cimg library, a couple of the overloads of draw_text take parameters named "font". Those seem like a reasonable starting point...