QTableWidget column resize - python

table is created in Qt Designer with settings:
In the main.py i just resized the columns:
self.table1.setColumnWidth(0, 150)
self.table1.setColumnWidth(1, 700)
If i run main.py i get:
My problem is: If i resize the window. I would like to keep the width of the Status column the same and only increase the width of the Description column. Has someone an idea how to do this?

You must set the setSectionResizeMode(index, mode) of the specific section of the horizontal header.
self.table1.horizontalHeader().setSectionResizeMode(
1, QtWidgets.QHeaderView.Stretch)

Related

How to set the height of an ipywidgets.Text?

I am trying:
from ipywidgets import Text, Layout
Text('test', layout=Layout(height='15px'))
but, it doesn't shrink the height of the Text widget frame. Instead, it just shows the frame cropped. See here:
How to properly get a Text widget with a specified frame height?

How to pad the location for the image on the label?

How to pad the location for the image on the label?
I am working on project in which the image is basically the size of the label and some text that I want to show isn't visible...when I remove the image, the label text is shown. I have to pad the location for the image on the label.
The label automatically resizes to account for the size of the image, so what you can do is, use the compound option to move the image to whichever position you prefer.
From a doc:
If you would like the Label widget to display both text and a graphic (either a bitmap or an image), the compound option specifies the relative orientation of the graphic relative to the text. Values may be any of tk.LEFT, tk.RIGHT, tk.CENTER, tk.BOTTOM, or tk.TOP. For example, if you specify compound=BOTTOM, the graphic will be displayed below the text.
So:
Label(root,text='Image 1',image=img,compound='top').pack()

Create a Qgis Icon based on an existing Icon

I am in need to create a Qgis icon similar to the existing Selection Qgis icon Select features by are or single click. I will create a new Icon to do exactly what the existing Qgis icon does and add some more script to it.
1 - I need to get the code for this existing Icon Select features by are or single click.
2 - Add the following code to it:
layer = iface.activeLayer()
selection = layer.selectedFeatures()
print len(selection)
for f in layer.selectedFeatures():
layer_xml = iface.addRasterLayer(f['tms'], f['name'])
Any help on that will be very appreciated.

Resizing of QMessageBox

I have created a QMessageBox as follows:
msg_box = QtGui.QMessageBox()
msg_box.setSizeGripEnabled(True)
msg_box.setIcon( QtGui.QMessageBox.Information )
msg_box.setText('The following files are not .jpg ')
msg_box.setInformativeText('No. of Items : {0}'.format(len(contents)))
msg_box.setDetailedText('{0}'.format('\n'.join([str(sel) for sel in img_sels])))
msg_box.setStandardButtons(QtGui.QMessageBox.Cancel)
msg_exec = msg_box.exec_()
User will select a handful of images, and if within the selections, if it consists of items that are not of jpeg/ .jpg format, these items' file path will be collated and be displayed in QMessageBox
One issue that I had is that, I am having difficulties in getting the QMessageBox to be resize or have the UI width conform according the the length or the text etc. As I am unable to do that, the popup ui displays the filepath almost like in a wrapped text format, somewhat unsightly.
Is there any other ways that I can do to improve the code and have it accommodate to the width etc?
If not, is there another QtGui command that I can consider to use it?

How to to center selected text in QTextBrowser

The code posted below creates QTextBrowser window filling it with 100 lines of text: starting from MESSAGE-0000 all the way to MESSAGE-0099
from PyQt4 import QtCore, QtGui
app=QtGui.QApplication([])
textBrowser = QtGui.QTextBrowser()
for i in range(100):
textBrowser.insertPlainText('MESSAGE-%04d'%i + '\n')
textBrowser.show()
app.exec_()
Question: How to find a line number where its text says: MESSAGE-0051, then select or highlight it and then scroll to it so the selected-highlightet line is positioned at the top edge of the QTextBrowser window, so the result would look like this:
How to achieve it?
If you search backwards, it will automatically scroll the selected line to the top of the viewport:
textBrowser.moveCursor(QtGui.QTextCursor.End)
textBrowser.find('MESSAGE-0051', QtGui.QTextDocument.FindBackward)
(Of course, if you search for say, MESSAGE-0095, it won't put the selected line at the top, because the view cannot scroll down that far).

Categories

Resources