PySide2 Popup - darken outside of popup - popup

I have created a popup window to display a custom context menu:
class FileActionDialog(QDialog):
def __init__(self, parent):
super().__init__(parent)
self.ui = Ui_ActionDialog()
self.ui.setupUi(self)
self.setWindowFlags(Qt.FramelessWindowHint | Qt.Popup)
self.setAttribute(Qt.WA_TranslucentBackground)
This is the design requirement:
Here is a rendered result:
The problem is that the outside of this popup doesn't become dark enough...
How can I darken outside?

Related

GTK4 ApplicationWindow that is also a ScrolledWindow?

Here is a minimal GTK 4 app written using the Python bindings, based on this tutorial. It displays a window with a very long block of text:
import sys
import gi
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw
class MainWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
long_label = Gtk.Label.new("Here is a very long chunk of text.\n" * 100)
self.set_child(long_label)
class MyApp(Adw.Application):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.connect('activate', self.on_activate)
def on_activate(self, app):
self.win = MainWindow(application=app)
self.win.present()
if __name__ == "__main__":
app = MyApp(application_id="com.example.GtkApplication")
app.run(sys.argv)
The tutorial uses the class Gtk.ApplicationWindow for the MainWindow, which lets you set the application_id in the main function and other convenient features.
However, the default Gtk.ApplicationWindow does not include a scrollbar. Rather than build one manually, it seems the best way to do this is to make my main window an instance of Gtk.ScrolledWindow, documented here, which lets you specify the scroll behavior etc. at a high level.
Unfortunately, dropping Gtk.ScrolledWindow in place of Gtk.ApplicationWindow causes an error:
TypeError: gobject `__main__+MainWindow' doesn't support property `application'
Is there a way to create a Gtk.ApplicationWindow that is also a Gtk.ScrolledWindow?
If not, what is the best way to get a scrollbar in my main window?'
(I have added the pygobject tag because it is the language of my MWE, but I think that my question is agnostic with respect to the binding language.)
A Gtk.ScrolledWindow isn't really a "window" per se as most people know it (it used to map to the very specific concept of a X11 Window). It's a widget that allows you to scroll through its child widget.
In other words, if you want an application window where you can scroll through the content, you would wrap your Gtk.Label with a Gtk.ScrolledWindow and you would then set that as the Gtk.ApplicationWindow's child.
In other words, your MainWindow would become:
class MainWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
long_label = Gtk.Label(label=("Here is a very long chunk of text.\n" * 100))
# Wrap a scrolled window around it
scrolled = Gtk.ScrolledWindow()
scrolled.set_child(long_label)
# Set it as the main child of the window
self.set_child(scrolled)

Adding checkable combobox in QGIS plugin builder plugin

I am developing a QGIS plugin in python and hit a roadblock when displaying my GUI. I am using the plugin builder framework to develop my plugin and I have trouble displaying a checkable combo box in a scrollArea in my GUI. The code with core functionality is as follows.
def run(self):
# Only create GUI ONCE in callback, so that it will only load when the plugin is started
if self.first_start == True:
self.first_start = False
# Sets up the pyqt user interface
self.dlg = EarthingToolDialog()
# Fetching the active layer in the QGIS project
layer = self.iface.activeLayer()
checkable_combo = CheckableComboBox()
# Going through each field of the layer
# and adding field names as items to the
# combo box
for j,field in enumerate(layer.fields()):
checkable_combo.addItem(str(field.name()))
# Setting the checked state to True by default
checkable_combo.setItemChecked(j, True)
# putting the check box inside the scroll area of the GUI
self.dlg.scrollArea.setWidget(checkable_combo)
self.dlg.scrollArea.setMinimumSize(QSize(700,400))
# show the dialog
self.dlg.show()
# Run the dialog event loop
self.dlg.exec_()
class EarthingToolDialog(QtWidgets.QDialog, FORM_CLASS):
def __init__(self, parent=None):
"""Constructor."""
super(EarthingToolDialog, self).__init__(parent)
self.setupUi(self)
class CheckableComboBox(QComboBox):
def __init__(self):
super().__init__()
self._changed = False
self.view().pressed.connect(self.handleItemPressed)
def setItemChecked(self, index, checked=False):
print('checked')
item = self.model().item(index, self.modelColumn()) # QStandardItem object
print(type(item))
if checked:
item.setCheckState(Qt.CheckState.Checked)
else:
item.setCheckState(Qt.CheckState.Unchecked)
def handleItemPressed(self, index):
print('pressed')
item = self.model().itemFromIndex(index)
if item.checkState() == Qt.Checked:
item.setCheckState(Qt.Unchecked)
else:
item.setCheckState(Qt.Checked)
self._changed = True
print('set ' + str(item.checkState()))
def hidePopup(self):
print('hide')
if not self._changed:
super().hidePopup()
self._changed = False
def itemChecked(self, index):
print('read')
item = self.model().item(index, self.modelColumn())
return item.checkState() == Qt.Checked
In summary, the run function is the main function called by the plugin when it is loaded. self.dlg is the instance of the actual pyqt python user interface. This is rendered with the help of the EarthingToolDialog class. The checkable combo box and it's functionalities are self contained in the CheckableComboBox class.
The run function executes without any error when the plugin is loaded but the checkboxes are not visible in the combobox. Just a normal combo box with a list of items (just the standard dropdown combo box) is seen on the GUI's scroll area and not the desired checkable combo box. The CheckableComboBox class was taken from https://morioh.com/p/d1e70112347c and it runs perfectly well in the demo code shown there.
I understand that this is a very specific question and it would be great if someone could figure out what the problem might be. Thanks in advance!
Within the run function, this piece of codes didn't work for me:
self.dlg.scrollArea.setWidget(checkable_combo)
self.dlg.scrollArea.setMinimumSize(QSize(700,400))
So instead, I use:
layout = QVBoxLayout()
layout.addWidget(checkable_combo)
self.dlg.setLayout(layout)
I didn't use directly this class (It was generated automatically since I use Plugin Builder, so in here I commented it):
class EarthingToolDialog(QtWidgets.QDialog, FORM_CLASS):
def __init__(self, parent=None):
"""Constructor."""
super(EarthingToolDialog, self).__init__(parent)
self.setupUi(self)
Now, in order to display checkable combo box, CheckableComboBox constructor is changed as :
def __init__(self):
super().__init__()
self._changed = False
self.view().pressed.connect(self.handleItemPressed)
delegate = QtWidgets.QStyledItemDelegate(self.view())
self.view().setItemDelegate(delegate)
The last two lines are from the answer listed here.
Codes display checkable combo box list with all items checked by default.

gtk3 GtkWindow title bar color

Using gtk3, how can I change the default GtkWindow titlebar color? Would it involve GtkStyleContext? I've only used GtkCssProvider.
You can't change the titlebar color from GTK. The titlebar is drawn by the window manager, and GTK doesn't "know" anything about it. You can only communicate with the window manager through "hints", such as whether the window should have a titlebar or what string should be displayed there, but the window manager is free to ignore them.
You can do it...
( at least on Linux )
What happens is that your window is being un-decorated then "decorated" with a header bar ( which happens to have a bloody "show_close_button", so I guess this is an intended use )
class base_ui(Gtk.Window):
def __init__(self):
# initializing self ( the window )
Gtk.Window.__init__(self, title="window title")
self.set_border_width(1)
self.set_default_size(800, 600)
# Create the header bar
hb = Gtk.HeaderBar()
# This is the id of the header bar to be used in the css file
hb.set_name("mw_hb")
# we can even set a close button ...
# you can add the other buttons as well, but have to do it yourself
hb.set_show_close_button(True)
# the effective text in the titlebar ( the window title )
# is props.title
hb.props.title = "win title"
# and here comes the sun - we set our headerbar as the new titlebar.
# Bazinga
self.set_titlebar(hb)

GXT LayoutContainer with scrollbar reports a client height value which includes the area below the scrollbar

I have this code which sets up a "main" container into which other modules of the application will go.
LayoutContainer c = new LayoutContainer();
c.setScrollMode(Scroll.ALWAYS);
parentContainer.add(c, <...>);
Then later on, I have the following as an event handler
pContainer = c; // pContainer is actually a parameter, but it has c's value
pContainer.removeAll();
pContainer.setLayout(new FitLayout());
LayoutContainer wrapperContainer = new LayoutContainer();
wrapperContainer.setLayout(new BorderLayout());
wrapperContainer.setBorders(false);
pContainer.add(wrapperContainer);
LayoutContainer west = pWestContentContainer;
BorderLayoutData westLayoutData = new BorderLayoutData(LayoutRegion.WEST);
westLayoutData.setSize(pWidth);
westLayoutData.setSplit(true);
wrapperContainer.add(west, westLayoutData);
LayoutContainer center = new LayoutContainer();
wrapperContainer.add(center, new BorderLayoutData(LayoutRegion.CENTER));
pCallback.withSplitContainer(center);
pContainer.layout();
So in effect, the container called 'west' here will be where the module's UI gets displayed. That module UI then does a simple rowlayout with two children. The botton child has RowData(1, 1) so it fills up all the available space.
My problem is that the c (parent) container reports a height and width value which includes the value underneath the scrollbars. What I would like is that the scrollbars show all the space excluding their own space.
This is a screenshot showing what I mean:
alt text http://img265.imageshack.us/img265/9206/scrollbar.png
Try adding padding equivalent to the scroll bars size 14px? on the container where the Scroll.Always is being applied

While switching to windows classic theme combo contribution item shirnks

I do have a problem with IToolbarManager. I have added a combo & spinner ot toolbar of a view like this
IToolbarManager mgr = getViewSite().getActionBars().getToolBarManager();
mgr.add(spinnerCntrAction);
spinnerCntrAction = new ControContribution(){
public Control createControl(){
//Creates composite
//Create a spinner and add that to composite
//return composite
}
};
In windows XP/Vista themes this spinner is shown correctly. But when program is run under windows classic theme , the spinner is shrinked and not shown correctly.
Is this a known problem ? Do you know any workaround/patch for this ?
Thanks
Jijoy
This is a bug in SWT. See http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg44671.html
Here is a workaround:
mgr.add(new DummyAction());
private static class DummyAction extends Action {
DummyAction() {
setEnabled(false);
setText(" ");
}
}
...
mgr.add(spinnerCntrAction);
This will cause the toolbar manager to make all control contributions the same size as the Action, so adjust the number of spaces in the Action text to get the desired result.