Get color of highlighted menu item - c++

How can I get default color of a highlighted menu item in qt?
I want to add a multiline menu item such as this. So I created a custom class inherited from QWidgetAction. I want to emulate native look&feel for this menu item. When the widget is under mouse, I need to change it's background color to default background of a highlighted menu item.

Related

Expandable list view with customized scrollbar in Qt

I want to build a widget like this one that we can find in Word :
So, there is a list view using a specific scrollbar with 3 buttons and no scroll.
When you click on the last button at the bottom right, a new list view with a classic scrollbar is shown over the previous list view (hidden when losing focus). So basically, the smae behavior as the one in Word.
We are already capable of displaying a list view with custom content.
My main concern is how to build the widget in the first image: the list view with the custom scrollbar (3 buttons, no scroll)?
What is the proper way to do this ?
I assume that you're implementing a subclass of QAbstractListView.
I don't believe you need a custom scrollbar - just put the scrollbar and the button into a QVBoxLayout; hide the button once it's checked (you could even connect its toggled() to its setHidden() for that).
At first hide the default scroll-bar by calling the QAbstractScrollArea::setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) method.
Then create your three buttons on the left side and connect the QPushButton::clicked() signals to some slots where you just scroll your list by calling the QAbstractItemView::scrollTo(index), QAbstractItemView::scrollToBottom() or QAbstractItemView::scrollToTop().
While it is correct that you could just build a custom widget consisting of a view with hidden scrollbars and add the buttons to the layout, connecting the signals/slots needed to provide the proper actions, you can also consider to implement your own QScrollBar class. QListView is derived from QAbstractScrollArea, which provides setVerticalScrollBar() so you can just set an object of it to be used by the view. The integration of scroll area and scroll bar should be much more straightforward this way, but you'll have to do the painting of the scroll bar's content yourself, or put a layout and the buttons in there (QScrollBar derives from QWidget, and you'll have to reimplement paintEvent()).

How to display tooltip on TitleBar

I have a child window derived from CMDIChildWndEx named as CTestTooltipMdiChildWnd, on CTestTooltipMdiChildWnd titlebar, I have drawn a custom icon which is initially disabled.
When user mouse over on this custom icon, I should get a tooltip displayed.
I get rect value of custom icon.
Any input how can I do this.Can anybody suggest any link where tutorial is available to understand.

Implement owner draw menu bar MFC

I want to create an owner draw menu bar (by menu bar I mean a bar that has the same width as the application window, not just to fit the menus) like the one in the image below
(Notice the menu item on the right and the background color for the bar that takes the full width of the window)
I only want the buttons to be customized (the size and the rectangle with a border on hover, and another effect when they're active), the menu popup itself has to be the Windows' default menu.
What have I done so far?
I managed to create the owner draw menu, but I have the following problems:
the menu bar rectangle is only as wide as the widths of the items summed up (I need it to take full window width)
all the menu items are styled uniformly (I only want the top buttons to be styled like that)
How can I get the desired look for my menu?

Setting and manipulating Icons in QT

I want to add icons in QMainWindow and when i will click that window it should perform some action like popup some window. So what should i use for the icon menu?
You could use the QToolButton class to accomplish this task.
It is possible to set it to only contain an image/icon without text.
l buttons are normally created when new QAction instances are created with QToolBar::addAction() or existing actions are added to a toolbar with QToolBar::addAction(). It is also possible to construct tool buttons in the same way as any other widget, and arrange them alongside other widgets in layouts.
A tool button's icon is set as QIcon. This makes it possible to specify different pixmaps for the disabled and active state. The disabled pixmap is used when the button's functionality is not available. The active pixmap is displayed when the button is auto-raised because the mouse pointer is hovering over it.
The button's look and dimension is adjustable with setToolButtonStyle() and setIconSize(). When used inside a QToolBar in a QMainWindow, the button automatically adjusts to QMainWindow's settings (see QMainWindow::setToolButtonStyle() and QMainWindow::setIconSize()). Instead of an icon, a tool button can also display an arrow symbol, specified with arrowType.
So, you would use these methods:
QAction * QToolBar::addAction(const QIcon & icon, const QString & text)
Creates a new action with the given icon and text. This action is added to the end of the toolbar.
and
toolButtonStyle : Qt::ToolButtonStyle
This property holds whether the tool button displays an icon only, text only, or text beside/below the icon.
The default is Qt::ToolButtonIconOnly.
To have the style of toolbuttons follow the system settings (as available in GNOME and KDE desktop environments), set this property to Qt::ToolButtonFollowStyle.
QToolButton automatically connects this slot to the relevant signal in the QMainWindow in which is resides.
As you can see, the default is icon only.

Highlighting items in TreeView C++ BUILDER

How can i change text color of some specifec item in TreeView?
TreeView is filled in program.
I mean i want to highlight some Treeview item by changing it text color.
You need to owner-draw the TreeView. It has OnCustomDrawItem and OnAdvancedCustomDrawItem events for that purpose. On a per-item basis, you can set the TreeView's Canvas->Font->Color property to whatever you want. Since you have access to the Canvas, you can draw whatever you want, not just customize the text.