QLineEdit: disable a part of text with or without mask - python

I would like to insert a mask in a qLineEdit widget, where at the left side the user can insert any text he wants (limited to the maximum limit of qLineEdit) and at the right there whould be a disabled text (mask).
Unfortunatelly I am not abled to upload a picture with the wanted result.
An example could be that the qLineEdit will accept lenght values in meters. The qLineEdit should have an disabled 'm' at the very right of the widget and at the left part the lenght can be inserted manually by the user.
f.e. [1234.567 m], where m is disabled
I am working with Python 2.7 and pyqt4.
Thanks in advance.

This should be easy enough using QLineEdit::setInputMask(), provided you don't have any special requirements regarding the behaviour of the input while using the mask; I found it hard to customize when it was set. Example:
input.setInputMask("0009.000 m")
As an alternative you can set a QDoubleValidator for the edit widget and add the units as separate label to the window layout right beside it.

Related

PyQT how to change layouts size

I am trying to make a GUI that is very similar to Spotify using PyQT
I've already designed the main window and I am struggling with applying the design to QT Creator.
This is what I want it to look like
But I'm trying to use Layouts in order to organize every widget.
For example
Image of the main window, split into 3 parts
like in the sketch I've made the software will be split into 3 parts, left bar, mid which is where the explore title is and right bar.
The problem I have is that I can't control the layouts size and the size of what's below them for example in the sketch the mid bar is wider than the right bar and the right bar is wider than the left bar but in the QTCreator I've no idea how to change the width and height of objects inside Layouts.
The first option (which I personally prefer) is to fill your layout with it's contents first (buttons, labels, etc.). This will already start to scale your layout, if there are more buttons in the middle bar than on the other bars. If your layout still isn't what you want it to be, you can use Spacers. They can push and pull puttons and position the in relation to other parts of the layout, as well as to the layout itself. The scaling will be adjusted automatically according to the spacers position.
This option has the advantage, that your application will be correctly scaled and not completely chaotic when it is run on a device with a display aspect ratio which is not the same as the one of the machine your developing it on.
There is, however, also a minimumSize and maximumSize attribute to the layouts, which provide a much more straightforward possibility, but sometimes cause your layouts to become very weird when adding or removing a button, or changing the text of a label. More on this option can be found in the Qt docs:
https://doc.qt.io/qt-5/qlayout.html

Best way of creating layout in pyqt5 to be resposive?

So I am curren]tly working on an app for image processing. I am using PyQt5 for this purpose. You can see how it looks like now on the picture below. My question is, what is the best way to make it responsive, meaning, if I resize the window, all the widgets will rescale as well. Right now I am using some groupboxes, Hlayouts, VLayouts.
Only thing that comes to my mind is to create a gridlayout, though I would like to know, if there is by any chance any other possibility how to easily do it, since there is quite a lot of widgets.
Also, I would like to ask about GroubBox widget. Down left I have four buttons which are in one groupbox whose border is set to none by self.tableButtonsGroupBox.setStyleSheet("tableButtonsGroupBox {border: none}"), but there is still visible the upper line. Is there way to get rid of it?
Thank you for suggestions in advance!

Column selection with mouse drag using Python/Tkinter Text function

I am developing a specialized text editor for a company. I am developing in Python 3.7.4 and I'm using Tkinter. One of the features I would like to develop is to select a range of columns/rows by dragging the mouse pointer from a starting point. If you're familiar with Notepad++, it is equivalent to their Alt + mouse drag feature. I've included a short video demonstrating this feature in Notepad++. https://www.youtube.com/watch?v=BEDURCPTrHo&feature=youtu.be
I have not found a similar keystroke combination in Tkinter that allows this within a Text box. I am familiar with most elements of the Text method, and know how to determine row/column index, selection range, insert/delete, bbox attributes, etc. And I also know how to bind mouse events (click, move, release). And finally I am aware of the notion of monospace fonts and calculating row/column for the mouse event x/y coordinates. I'm just wondering if anybody has written any code to do this, or knows of a Tkinter Text method feature that I may be overlooking.
Thanks in advance for your help.

How can I add scrollable whitespace at the bottom of a QTreeView

When expanding an item at the bottom of a QTreeView, the view does not automatically scroll to show the newly-expanded items. I can fix this by detecting expansion and performing the scroll myself when appropriate.
However, I would instead like to allow the user to scroll the view farther than is currently allowed. Currently, if the tree is too tall to fit in the visible area, the view can be scrolled only until the bottom-most row comes into view.
I believe this should be doable by tricking the QTreeView's size calculation, but even after source diving I don't understand the interaction between QTreeView and its base QAbstractScrollArea well enough to know what to poke, or where to start poking.
If all else fails I may just add some dummy, non-editable rows to my data model.
you can add extra white space to the treeview by increasing its vertical scrollbar maximum value. Smth like this:
max = self.treeview.verticalScrollBar().maximum()
self.treeview.verticalScrollBar().setMaximum(max*2)
hope this helps, regards

Creating a Selection tool using PyGtk

Can anyone help or point me in the right direction for figuring out how to create a drag and draw rectangular box to be used as a selection tool in PyGtk? I am presently using an event box with a drawable window and the user can click once in the upper left and once in the lower right corner of the portion of image they would like to choose which will then draw a rectangle over the selection, but a drag and draw rectangle will allow the user to better adjust and get better accuracy.
I have looked quite a few places for information or a tutorial on this but I haven't found much. I am relatively new to Gtk+ so perhaps this is so simple that no one has to ask.
Actually, this doesn't seem all that lamebrained at all. It is actually quite specific, and a little challenging.
I'll give you the steps to start you off, but as you're beginning (and you didn't post any specific code), it would be better for you to create the code yourself based on documentation and my hints.
By the way, look up the official PyGTK documentation - that should be your definitive source for all the objects and functions of PyGTK. It is very well written and exhaustive, and I rarely have to look more than five minutes to find what I need.
What I suggest you do is use three signals, connected to your drawing area.
button-press-event
button-release-event
motion-notify-event
Create three callbacks (tutorial here), one for each event. Connect your drawing area to your events and callbacks (again, see tutorial. You may need to go through a few pages on it.).
You are going to also need to create two boolean variables on the global level (above the main class, at the same level you import modules.) The first controls whether the selection tool is chosen (call it "Select_On"), and the second for if it is active (call it "Select_Active")
On the button you use to start the select tool, set "Select_On" to "True". This should probably be a toggle button, so make sure you set it up so "Select_On" gets set to off if you toggle the button off.
On button-press-event, create the object for selecting. What you're going with now actually should work well. Also, set "Select_Active" to "True".
On motion-notify-event, change the size of your object based on cursor position. Refer to that documentation for that particular kind of object to learn how to change its size, and refer here for how to get the cursor position.
Be prepared to write an algorithm to determine how to change the size of the selection object based on the cursor position. If you need help with that, feel free to ask for it in a separate question.
On button-release-event, set "Select_Active" to "False", and call all your code for actually confirming the selection.
As an aside, the benefit to using the "motion-notify-event" is that, as soon as the cursor leaves the widget you're selection in, the selection box stops changes sizes. The cursor must re-enter the widget to continue changing the selection box size.
I hope all that works for you, and wishing you the very best on your project!

Categories

Resources