Styling a GeoDjango widget - django

I have been trying to style the GeoDjango OSMWidget (for Polygon drawing) for ages but can't work out how to make it flexible. Setting the map width and map height is all fine for a fixed page size but what happens if someone snaps their browser window to half-screen? A fixed map width does not react to these changes and becomes an unwieldily feature so fast it's painful. The widgets also don't respond to any style information given in the html doc via Tailwind.
Here is what the GeoDjango documentation suggests for widget styling:
widgets = {
'geometry': forms.OSMWidget(attrs={
'map_width': 1000,
'map_height': 400,
'default_zoom': 7.5 }),
}
Other widgets, such as forms.Select have the option for a style attribute where custom css can be defined. The map widgets ignore this completely.
How can I force this map widget to respond to my css demands? I want flexible widgets, goddamit!
*Bonus points for integration with tailwind

Related

Customise button in QT

I need to create a toggle button in qt and it should look like the below image. It should show the ON image when it is turned on and remain at this state until it is toggled again. It should show the OFF image in the off case. Please help me on this.
You can use images as an icon (sadly, it won't scale with button by default), create a class which would paint those images in the handler for paint event, or you can use those images in QSS stylesheet. QSS is CSS 2.0 analog for Qt's GUI elements.
Note that after using stylesheet all changes to visuals of said element should be done through changes to stylesheet as well.
THose styles can be set through form editor by right-clicking a widget and choosing "Change stylesheet" or through code directly by calling setStyleSheet, depending which workflow you prefer.
button->setStyleSheet(
"QPushButton { border-image: url(:/Resources/chbUnchecked.png); }"
"QPushButton::checked { border-image: url(:/Resources/chbChecked.png); }" );
border-image Scales image to border limits, replacing standard border.There is also a background-image which fills widget's surface with regular repeats.
To limit this change only for checkable buttons:
button->setStyleSheet(
"QPushButton[checkable="true"] { border-image: url(:/Resources/chbUnchecked.png); }"
"QPushButton::checked[checkable="true"] { border-image: url(:/Resources/chbChecked.png); }" );
:/Resources/ is a path within app's resources.
QSS syntax: https://doc.qt.io/Qt-5/stylesheet-syntax.html
Note that QSS have selectors, so it's it have same "Cascading" ability as CSS. You can assign styles bulk based on hierarchical location on GUI, class-inheritances, class names, quasi-states and names.
If you set style above to a window, all instances of QPushButton within that window would have said style. If you define a new class for such Button, you can use its name instead of standard button class, although QSS for base class would apply to it.
the easiest way is to add the on-off images to your project as resources
then set the button as checkable and in its properties set the images to be rendered when is selected or not..(under icon -> selected on and selected off)
of course you have create images with a properly geometry... in the screenshot they look pretty small because I borrow them from your post..
:)

Qt Swipe-animation to other .ui file

I'm working on an application with a login page and a registration page. All the widgets on the login form have been placed using the design tab in Qt creator.
How would I go about animating all widgets on the login at the same time to swipe off to the side and introduce the register page - stored in another ui file? I tried adding all widgets to a QStackedWidget and animate that - but every widget I add to it vanishes from the form.
I just can't seem to figure this out - any help is very appreciated!
Instead of using QStackedWidget just create the new widget on top of the previous and offscreen, and use the animation to slide it into place. You don't need to animate all widgets, just the container widget, the rest will move with it.
Or better off, if you are going to make animated GUI, go for a QML UI instead. It is much easier to work with.

resizing window in qt without using standard layouts

I’m using QT Creator and I'm having difficulty figuring out how to enable resizing when running the widget. I know when you apply a layout (horizontal, vertical, and grid) it enables resizing, but when I use these standard layouts they reconfigure all of the widgets I have put in the window. I’m trying to enable resizing but have all of the widgets I put in the window where I want them to be.
Check the different layout behaviours. Use the horizontal and vertical 'spring' widget to make the other widgets to stay where they are. Use nested layouts when you want to combine the view of the widgets.

Customizing QT QTreeView with custom widgets

In my raster drawing program I need to create a layers interface like in Photoshop or Sketchbook Pro. I read the documentation and figured out that I have to use QTreeView. But I didn't find a lot of information in the documentation about creating QTreeView with custom widgets. So:
1) How to insert custom widgets into tree view?
2) What is the difference between QTreeView and QTreeWidget?
3) What is the difference between QAbstractItemModel and qitemdelegate?
4) Any examples/articles/guides?
5) Maybe I should use something else?
QTreeWidget is a model and a view in one class, it's called a convenience view. It works against the good practice of separatng the views and the models, and probably shouldn't be used in a system where the notion of document layers belongs in the document handling code.
QTreeView is just a view, without any bundled models. When you have a model, you can set it on a view, making the view display the model.
A QAbstractItemModel is the data model. It has nothing to do with views or delegates at all - the model can exist and be useful without a view at all.
A delegate provides display and editing widgets for items of data in a view. It is a property of the view, not of the model. Different views can show the same model using different delegates, all at the same time.
Although the delegate lets you provide the custom widgets you're after, its use may be unnecessary. If the item you display has static contents, you can simply provide a QImage or a QPixmap as the data.
Special for your case (5): DON'T use any of QTreeView, QStandardItemModel and other such classes. If you need interaction with widgets + if you need widgets to be animated then you should use simple QScrollArea with QVBoxLayout inside of it.
Qt MVC is designed to process big amount of cognate data. It is not designed to provide widget-based interaction. So, if you want to "assign" one widget to each item and to interact with them - you will have a lot of problems with implementing delegates (tracking mouse events, providing editor's factory). Ofc, you may create your own delegates with custom drawing and custom processing of mouse events, but it's much easy to use simple widgets.

How can I add multiple icons to an individual TreeView item?

I am trying to display multiple icons to the Treeview item but it is not displaying all the icons, it displays only one.
I am using the following code:
CImageList m_imageState;
m_cTree.m_imageState.Create(16, 16, ILC_MASK, 0, 4);
m_cTree.m_imageState.Add(&bm, RGB(255,255,0));
m_cTree.m_imageState.Add(&bm2, RGB(255,0,255));
m_cTree.m_imageState.Add(&bm, RGB(255,255,0));
m_cTree.m_imageState.Add(&bm1, RGB(0,255,255));
m_cTree.SetImageList( &(m_cTree.m_imageState), TVSIL_NORMAL );
But when I see Treeview, item displays only one icon.
Is it possible to display multiple icons with Treeview item?
Please suggest how can I do this.
Correct, only one icon will be displayed per item in a TreeView control. This is by design, a hard limitation of the native control that the MFC library wraps.
The only way you're going to be able to display multiple icons per item is owner drawing. It's a pretty difficult task for a TreeView control, not nearly as easy as owner drawing a button or a label control. Make sure that you really this need this functionality, and consider whether there's a better way of displaying the relevant information to your users.
Alternatively, you could create custom bitmaps that combine multiple images next to one another, and add those to your ImageList. The resulting images will be wider than they are tall, but the control doesn't care: it will display whatever size images you specify, as long as all the images in the image list have the same dimensions. This is definitely a hack, but it might work, depending on your needs.