QML TreeView get the click event for second child only - qt

I have a TreeView and I am generating C++ model using QStandardItemModel class.
I want to get the click event when user clicks on every 2nd child in the tree.
Item-1
|
|
Item-1.1 <-- Detect click on this Item
| |
| Item-1.1.1
| Item-1.1.2
|
Item-1.2 <-- Detect click on this Item
| |
| Item-1.2.1
| Item-1.2.2
|
Item-2
|
|
Item-2.1 <-- Detect click on this Item
| |
| Item-2.1.1
| Item-2.1.2
|
I have tried below code to detect the click but it is generating click for 3rd level child also.
TreeView {
model: myCppModel
onClicked: {
if (index.parent.row >= 0) {
if (index.row > 0) {
console.log(myCppModel.data(index));
}
}
}
}

Related

Position of the "Apply" button in QDialogButtonBox

I would like to have a QDialogButtonBox with three buttons in this particular order:
Ok | Apply | Cancel
Is it possible to reorder the buttons to put Apply in the center?
The button layout is platform specific.
Windows - Ok | Cancel | Apply
OS X - Apply | Cancel | Ok
KDE - Ok | Apply | Cancel
GNOME - Apply | Cancel | Ok
There is two way to force use non standard layout.
You can subclass QProxyStyle and reimplement styleHint method, to provide custom style for QStyle::SH_DialogButtonLayout styleHint.
class KdeStyle : public QProxyStyle
{
public:
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const override
{
if (stylehint == SH_DialogButtonLayout)
return QDialogButtonBox::KdeLayout;
return QProxyStyle::styleHint(stylehint, opt, widget, returnData);
}
};
Then apply custom style to application.
qApp->setStyle(new KdeStyle());
Another way to do it, is using stylesheets. button-layout property specify the layout of buttons in a QDialogButtonBox or a QMessageBox. The possible values are 0 (WinLayout), 1 (MacLayout), 2 (KdeLayout), and 3 (GnomeLayout).
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel);
buttonBox->setStyleSheet("* { button-layout: 2 }");

Can I mix a fixed left offset with a relative width in CSS?

I have a situation like this:
+------------------------------------------------------------------------------+
| |
| +---------------------------------------------------+ |
| | | |
| <- fixed width -> | <- flexible width -> | |
| | | |
| +---------------------------------------------------+ |
| |
| <- flexible width -> |
| |
+------------------------------------------------------------------------------+
What this is supposed to represent is an outer DIV and its child (also a DIV) appearing in the browser. The outer div takes up, say, 90% of the viewable area (width: 90%). If the screen is resized it will resize. It's OK for it to have a minimum width.
The child div is meant to stay a fixed number of pixel from the left of the outer DIV (left: 200px).
I would like it to resize with its parent (i.e. childWidth = (parentWidth - 200) * .9).
Is it possible to do this with CSS / how?
Yes, just add right: 0px to the inner div in addition to left.
(also, try jsfiddle.net instead of ascii ;))

How to dynamically hide/show widgets?

I want to dynamically hide/show widget like so:
Default:
|-------|
| |
| text |
| editor|
|-------|
With webkit preview:
|-------|-------|
| | |
| text | web |
| editor| widget|
|-------|-------|
With okular preview:
|-------|-------|
| | |
| text | okular|
| editor| widget|
|-------|-------|
Just add all your widgets into the layout and use QWidget::hide(), QWidget::show() when needed.
For more complex situations you can use The State Machine Framework.

How to make images to go out of the div when width is over the max-width?

I have a page with a text and images inside it, with a style float:right.
I'd like to set max-width for the text, but let the images to go outside the text.
Is it possible to do it with a pure css, without javascript?
This is how I would like to see it on a normal screen and wide screen:
+----------------------+ +-------------------+--------------+
| | | | |
| TEXT TEXT | | | |
| +-------+ | | +-------+ |
| | | | | | | |
| | IMG | | TEXT | | IMG | |
| | | | | | | |
| +-------+ | | +-------+ |
| | | | |
| TEXT TEXT | | | |
| | | TEXT | BACKGROUND |
| | | | |
| +-------+ | | +-------+ |
| | | | | | | |
| | IMG | | | | IMG | |
| | | | TEXT | | | |
| +-------+ | | +-------+ |
| | | | |
| TEXT TEXT | | | |
| | | | |
+----------------------+ +-------------------+--------------+
<-----MAX-WIDTH----->
Use CSS3 media queries:
#media screen and (min-width: 600px) {
.aClass {}
.anotherClass {}
/* properties in here only apply when the viewport is wider than 600px */
}
Using this method you can have the text flow around the images by default, but if the viewport is wide then you override that CSS and position the images outside the container div using negative margins or absolute positioning.
More about responsive web design with CSS.
style="position:absolute;right:100px;" may give you what you want. Note that you might not need to specify float:right if you have position:absolute.
You should not have img that are inside a div appear outside of that div. The images should be maybe siblings of the div instead of children.

How to reset parent child relationship between nested div

I am new to CSS designing and not aware of most of the properties of CSS. I am creating a layout for a web page. I am using div in my layout.
My structure is somewhat like this
<div id="content1_bg">
<div>
<div class="content1_title_img_div"></div>
<div class="content1_title_txt_div"></div>
<div class="content1_dvider_div"></div>
<div class="content1_content_div"></div>
</div>
<div></div>
<div></div>
</div>
For this my CSS is
#content1_bg div{width:250px;height:220px;float:left;border:3px solid blue; margin:20px;}
.content1_title_img_div{width:50px;height:100px;}
.content1_title_txt_div{width:150px;height:100px;}
.content1_dvider_div{width:100%;height:10%;clear:both;}
.content1_content_div{width:100%;height:50%;clear:both;}
For this layout i was expecting my design to be like
----------------
|BOX1 BOX2 |
----------------
| BOX 3 |
----------------
| BOX 4 |
----------------
But on using my css layout is somewhat like this
--------------------
| | | | |
|BOX1| | BOX2| |
| | | | |
--------------------
| |
|BOX3|
| |
--------------------
| |
|BOX4|
| |
Basically i want my inner div's not to inherit the properties of outer div. How can i remove this inheritance relationship between parent div and child div
You have to override the properties in the child.
#content1_bg div
means that all the divs coming inside an element with id #content1_bg will have the said properties.
If you need to apply these properties only to a selected set of divs then you can assign a class to the selected divs and change your css definition as '#content1_bg div.some_class'.
Then assign the class some_class to the selected divs

Resources