I am using QT 4.3. I have created one custom widget plugin. I could be able to show it in the desiner tool box as well as use it on the form with no problem.
This custom widget internally holds QGroupBox, QLabel, QTextEdit.
Now I want to apply the styles to individual componets of this custom widget.
I want to expose these internal conrols as sub-control and style them. This would be similar to tear subcontrol of QTabWidget. In style sheet we can refer it as QTabWidget::tear...
Is there any way by which I can do similar thing with my custom widget?
The subcontrols are defined in the (internal to Qt) knownPseudoElements array in qstylesheetstyle.cpp, so you won't be able to add your own pseudoelements. However, you can use the ID Selector feature to address individual controls in your widget. For example, if the names of your QGroupBox, QLabel, and QTextEdit are group, label, and edit, you can use:
#group {color:green} #label {color:blue} #edit {background-color:red}
to change the sub-widgets
Related
I have pre-existing code which has a tree view like appearance but doesn't actually use QTreeView (uses QListWidget with custom paint).
I am tasked to add the indentation between the parent and child objects, but I can't able to find how to get the style default indentation width from QStyle. The program has to run on a variety of os and allow to use custom stylesheets. So it's important to get this option from QStyle.
Regards.
found this in qt sources
have to use QStyle::pixelMetric with QStyle::PM_TreeViewIndentation
inside your widget's procedure
ident = style()->pixelMetric(QStyle::PM_TreeViewIndentation)
I wanted to have a QTreeView with icons ( which act as a checkbox ) followed by some text from a subclass of QAbstractItemModel. I cannot modify or change the structure of this QAbstractItemModel.
When I use this QAbstractItemModel with QTreeview, it shows checkbox followed by some text and performs the intended function required. I just wanted to change this check box to on and off icons.
I found this:- Customizing the checkboxes of the items of a QTreeView
But, I cannot use stylesheets in my case as the icon I want to use some system icons which are loaded using icon loader which returns a KIcon instance ( subclass of QIcon ).
What would be the right way of doing this?
I saw this tutorial and tried creating an editor for a checkbox. But, how should I register editor as QVariant does not have Qt::CheckStateRole type?
I tried using Qt::Int, but it doesn't works
In Qt widget application, I'd like to have a common base view for all my dialogs, so that I could inherit other classes from it.
This "base/common" view would contain initially a set of buttons at the bottom and a custom frame with data at the top. A place in the middle would be used by derived classes for placing view-specific contents. If the common dialog style changes in the future, changes will be applied in one class only.
Is there any way to use such approach in Qt, since ui files are processed with 'uic' to create classes? Ideally would be to not to lose the ability of using the gui designer, at least for the derived classes.
Any hints much appreciated.
You can make your "base view" as its own ui file with a big QFrame in the middle with nothing in it and name it contentsFrame. Then create your other widgets you want to place inside the empty contentsFrame in designer.
Now you have a couple options. You can have both open side by side in designer, click on your contents widget, select all, and drag everything to your contentsFrame. Then just hit save as and save it as a different widget. If you aren't afraid to leave designer for a tiny bit, you can add your contents widget to the base widget in code. Either way, make sure you are setting the layout for your contentsFrame or everything will look like garbage.
I am trying to write a program that will use a tabbed document interface (TDI) like seen in Notepad++ or most web browsers. I know how to build GUIs using Qt Designer, and code in Qt C++ (after a few days of playing around).
I have created an example of what each page widget will look like using Designer, and now I want to add the ability to create and testroy tabs at runtime, each containing a unique instance of the page widget. However, I have no idea how to do this without adding a class that extends QWidget, and building the page widget with code. I could go down this route, but I'm sure there must be a better way of creating a TDI; but I can't find any tutorials or examples of how to do this.
Does anyone have any suggestions?
For creating tab interfaces you should look into QTabWidget.
It is a container widget included in Qt Designer which automatically handles operations on tabs. It has several build in methods for manipulating its tabs and theirs contents.
Each page of QTabWidget is handled separately and can have different layouts and functionality.
If you want to include several different objects to one page assign a layout to it and then assign the objects to the layout.
Qt's QTabBar has functionality to set the colour of text on each tab.
I'd like my application to be able to set the background colour of each tab. From what I can see, QTabBar isn't easily modifiable (e.g. by inheritance or changing a property) to do this.
This leaves me with the option of copying the QTabBar code wholesale into my (GPL) application, then modifying the class name (i.e. MyQTabBar), then adding my functionality. Is this the preferred method, or is there a better way?
There is definitely a better way :) You should be able to do what you want using stylesheets. This article covers some of this with a QTabWidget which contains a QTabBar.