Is it possible to have individual indentation of items in a QTreeWidget?
In specific, I have have a column containing both text, icon and for some of them a CheckBox. The items without a CheckBox gets shifted to the left so the indentation of the icon and the text is not inline with the others. Could maybe be fixed with a hidden CheckBox if that is possible?
Maybe the use of Delegates will give you a nice and proper implementation. You'll have the opportunity to re-implement the paint() and sizeHint() methods, and therefore, choose the way your QTreeWidgetItem are being drawn...
More documentation here : http://doc.trolltech.com/4.6/model-view-delegate.html
An example : http://doc.trolltech.com/4.6/itemviews-pixelator.html
Hope it helps a bit !
You can try using the QWidget::setContentMargins() on the widget returned by QTreeWidget::itemWidget().
Related
I have some QLabels in a QWindow. They might have some space in common. I want to know how can I change label's depth. In default situation the label which defined later is on the previews ones.
You can define an indent for each widget and call raise_ function in sort of their indent.
for label in labels:
label.raise_()
you should use raise, like :
labelname.raise_()
All widgets have methods for this.
widget.stackUnder(another_widget) #relative postition
widget.lower() # send to the bottom
widget.raise_() # send to the top
See documentation on QWidget
I add a layout in a dialog and sometimes I want it and all its containing widgets to hide. How to implement it? I try layout->setEnable(false), but it doesn't seem to work in my tests.
You can't do that. You should add a widget in your form, put children inside the widget and assign desired layout to the widget. The behavior will be generally the same, but you can use setVisible or hide methods of the widget.
Transform QLayout to QWidget first, then you can use QWidget->hide().
Is there a way to set a tool tip text for the close button & float button in a QDockWidget ?
As ixSci mentioned, using setTitleBarWidget() is a potential way of solving this problem. Having said that I was looking for a much simpler solution, ideally using QSS (Qt Style Sheets). So after digging into the source code of QDockWidget I found an alternative way which suits my requirement better.
I wanted to find the place these float and close buttons are created. That is inside QDockWidgetPrivate::init() method in QDockWidget.cpp.
As for an example, the float button is created like this:
QAbstractButton *button = new QDockWidgetTitleButton(q);
button->setObjectName(QLatin1String("qt_dockwidget_floatbutton"));
QObject::connect(button, SIGNAL(clicked()), q, SLOT(_q_toggleTopLevel()));
layout->setWidgetForRole(QDockWidgetLayout::FloatButton, button);
Now all I need is to use the flexibility of Qt Style Sheets, for that I need only the Object Name, in this case it's "qt_dockwidget_floatbutton"
So all you need to do, to set tooltips for Close and Float buttons of a QDockWidget, is to add following two lines of styles in your application style sheet
QAbstractButton#qt_dockwidget_closebutton{qproperty-toolTip: "Close";}
QAbstractButton#qt_dockwidget_floatbutton{qproperty-toolTip: "Restore";}
You can implement whatever title widget you want and set it with setTitleBarWidget(). In that widget you can add whatever buttons with tooltips you need.
I've got QListWidget as a child inside QPlainTextEdit for purposes of completion suggestions.
Suggestion list is displayed under cursor and when line is almost full, part of list widget is cropped by the border of text edit. Is there any possibility to force child widget show out of parent widget region?
An idea I have, is to make the text and list edit elements "siblings", i. e. add them to the same parent. But this would require my event handling mechanism (as I suppose parent-child relation between those two elements).
I think there must be a way to achieve this, as I studied Katepart component and there is KateCompletionWidget (displays suggestions) that is direct child of KateView and when I run it (e. g. Kate text editor), the list is shown across text edit border.
There's no way for a child to paint outside of a parent's QWidget rect, unfortunately. Your sibling approach is a popular solution to this problem. Another approach is for the child to notify the parent of what it wants to draw, but this can be a bit more advanced because you have to re-implement paint events.
Today I found a possibly viable way -- it's based on setWindowFlags(Qt::ToolTip) method of QListWidget element. There's, however, some slight change in positioning and event handling.
Is it possible to have a two-line element in a cell (QTableWidgetItem) of a QTableWidget with different styles per line? I want to have the first line bold and the second line not bold. Or can I add two QTableWidgetItems in one cell? Do a cellspan somehow?
Cheers
Matthias
Simple way :
Checkout the setCellWidget method of QTableWidget.
If you replace the default widget with QTextEdit, you can get rich text formatting capability.
Better way :
Use a custom QStyledItemDelegate. You can see an example here
I hope this helps.