I have a QScrollArea and I scroll down automatically, but it does not work completely - it does scroll only until half. What might be wrong with my code? I use the vertical ScrollBar. Maybe there is a problem with setSizePolicy?
code:
import sys
from PySide import QtGui, QtCore
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.setStyleSheet("QMainWindow {background: #010206;}");
self.inicar()
def inicar(self):
groupBox = QtGui.QGroupBox('', self)
groupBox.setGeometry(100, 100, 500, 340)
groupBox.setStyleSheet('QGroupBox {border: 2px solid #101010; border-radius: 3px;}');
label = QtGui.QLabel(self)
label.setText('prueba asda asd asdad asdasdadadasd prueba asda asd asdad asdasdadadasd')
label.setWordWrap(True)
label.setStyleSheet('QLabel {color: #6E6E6E;float: left;border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
label2 = QtGui.QLabel(self)
label2.setText('hola que tal asdasdasd asd asdasdad asdas')
label2.setWordWrap(True)
label2.setStyleSheet('QLabel {color: #2F6120;float: right; border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
label3 = QtGui.QLabel(self)
label3.setText('prueba')
label3.setWordWrap(True)
label3.setStyleSheet('QLabel {color: #6E6E6E;float: left;border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
label4 = QtGui.QLabel(self)
label4.setText('hola que tal asdasdasd asd asdasdad asdas')
label4.setWordWrap(True)
label4.setStyleSheet('QLabel {color: #2F6120;float: right; border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
label5 = QtGui.QLabel(self)
label5.setText('hola que tal asdasdasd asd asdasdad asdas')
label5.setWordWrap(True)
label5.setStyleSheet('QLabel {color: #2F6120;float: right; border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
label6 = QtGui.QLabel(self)
label6.setText('hola que tal asdasdasd asd asdasdad asdas')
label6.setWordWrap(True)
label6.setStyleSheet('QLabel {color: #2F6120;float: right; border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
label7 = QtGui.QLabel(self)
label7.setText('prueba asda asd asdad asdasdadadasd')
label7.setWordWrap(True)
label7.setStyleSheet('QLabel {color: #6E6E6E;float: left;border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
label8 = QtGui.QLabel(self)
label8.setText('prueba asda asd asdad asdasdadadasd prueba asda asd asdad asdasdadadasd')
label8.setWordWrap(True)
label8.setStyleSheet('QLabel {color: #6E6E6E;float: left;border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
label9 = QtGui.QLabel(self)
label9.setText('hola que tal asdasdasd asd asdasdad asdas')
label9.setWordWrap(True)
label9.setStyleSheet('QLabel {color: #2F6120;float: right; border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
label10 = QtGui.QLabel(self)
label10.setText('prueba asda asd asdad asdasdadadasd')
label10.setWordWrap(True)
label10.setStyleSheet('QLabel {color: #6E6E6E;border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
label11 = QtGui.QLabel(self)
label11.setText('hola que tal asdasdasd asd asdasdad asdas')
label11.setWordWrap(True)
label11.setStyleSheet('QLabel {color: #2F6120; border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
label12 = QtGui.QLabel(self)
label12.setText('hola que tal asdasdasd asd asdasdad asdas')
label12.setWordWrap(True)
label12.setStyleSheet('QLabel {color: #2F6120;float: right; border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
label13 = QtGui.QLabel(self)
label13.setText('hola que tal asdasdasd asd asdasdad asdas')
label13.setWordWrap(True)
label13.setStyleSheet('QLabel {color: #2F6120;float: right; border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
label14 = QtGui.QLabel(self)
label14.setText('prueba asda asd asdad asdasdadadasd')
label14.setWordWrap(True)
label14.setStyleSheet('QLabel {color: #6E6E6E;float: left;border: 2px solid #071918; border-radius: 3px; padding-top: 2px; padding-bottom: 2px; padding-left: 3px; padding-right: 2px;}');
vbox = QtGui.QVBoxLayout()
vbox.addWidget(label)
vbox.addWidget(label2)
vbox.addWidget(label3)
vbox.addWidget(label4)
vbox.addWidget(label5)
vbox.addWidget(label6)
vbox.addWidget(label7)
vbox.addWidget(label8)
vbox.addWidget(label9)
vbox.addWidget(label10)
vbox.addWidget(label11)
vbox.addWidget(label12)
vbox.addWidget(label13)
vbox.addWidget(label14)
vbox.addStretch(1)
groupBox.setLayout(vbox)
scroll = QtGui.QScrollArea(self)
scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
scroll.setWidgetResizable(True)
scroll.setGeometry(100, 80, 500, 340)
scroll.setStyleSheet('QScrollArea {background: #010206; border: 2px solid #101010; border-radius: 3px;}');
scroll.setWidget(groupBox)
label.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
label2.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
label3.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
label4.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
label5.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
label6.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
label7.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
label8.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
label9.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
label10.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
label11.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
label12.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
label13.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
label14.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
maximumY = scroll.verticalScrollBar().maximum()
scroll.verticalScrollBar().setSliderPosition(maximumY)
self.setGeometry(350, 145, 730, 500)
self.setFixedSize(730, 500)
self.setWindowTitle('Mensajes')
self.show()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
w = Window()
sys.exit(app.exec_())
The geometry of widget are not initiated. So you have to wait it after initiate successful, You can set set slider position. In your code is after call method self.show();
.
.
label14.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
self.setGeometry(350, 145, 730, 500)
self.setFixedSize(730, 500)
self.setWindowTitle('Mensajes')
self.show()
maximumY = scroll.verticalScrollBar().maximum()
scroll.verticalScrollBar().setSliderPosition(maximumY)
In the other-hand, You can create your custom QtGui.QScrollArea to auto scroll down when size of QtGui.QScrollArea has been changed. Implement method QAbstractScrollArea.resizeEvent (self, QResizeEvent);
class QScrollEndArea (QtGui.QScrollArea):
def resizeEvent (self, eventQResizeEvent):
QtGui.QScrollArea.resizeEvent(self, eventQResizeEvent)
self.verticalScrollBar().setSliderPosition(self.verticalScrollBar().maximum())
And replace QtGui.QScrollArea to your custom QScrollEndArea in your code, benefit is your not to handle set position size in your main widget, it handle itself;
scroll = QScrollEndArea(self)
Related
Input Element:
<input type="text" auto_complete_item_format="<b xmlns="none">[_full_name]</b>" auto_complete_display_field="_full_name" auto_complete_id_field="suburb_id" auto_complete_search_fields="_full_name,suburb" auto_complete_minimum_characters="1" auto_complete_data_source_web_method="" auto_complete_data_source_object="" auto_complete_data_source_function="get_suburb_suggestions" auto_complete_width="300px" onblur="smart_update(this);" onkeypress="smart_keypress(this, event); " onchange="smart_date_onchange(this); " selected_id="-1" original_value="" value="3000" smart_field_type="auto_complete" class="smart_auto_complete" id="suburb" name="suburb" field="jims.addresses.smart_table.suburb" record_id="-1" bind="True" auto_complete_cursor="2" autocomplete="off" fdprocessedid="5bithf" auto_complete_last_search_string="300" selected_row_index="-1" style="width: 300px;">
Suggestions List:
<div id="suburb_list" name="suburb_list" style="display: none; position: absolute; border: 1px solid rgb(0, 0, 0); z-index: 100; left: 533px; height: 400px; width: 300px; background-color: white; opacity: 0.93; overflow: auto;"><div id="suburb_list_item_0" list_index="0" row_index="0" style="border-width: 1px; border-color: rgb(170, 170, 170); border-style: solid; background-color: rgb(221, 221, 221); padding: 3px;"><b xmlns="none">150 Lonsdale Street, Melbourne 3000 VIC</b></div><div id="suburb_list_item_1" list_index="1" row_index="1" style="border-width: 1px; border-color: rgb(170, 170, 170); border-style: solid; background-color: rgb(255, 255, 255); padding: 3px;"><b xmlns="none">1 Elizabeth Street, Melbourne 3000 VIC</b></div><div id="suburb_list_item_2" list_index="2" row_index="4" style="border-width: 1px; border-color: rgb(170, 170, 170); border-style: solid; background-color: lightblue; padding: 3px;"><b xmlns="none">Carlton 3000 VIC</b></div><div id="suburb_list_item_3" list_index="3" row_index="5" style="border-width: 1px; border-color: rgb(170, 170, 170); border-style: solid; background-color: rgb(255, 255, 255); padding: 3px;"><b xmlns="none">Docklands 3000 VIC</b></div><div id="suburb_list_item_4" list_index="4" row_index="10" style="border-width: 1px; border-color: rgb(170, 170, 170); border-style: solid; background-color: rgb(221, 221, 221); padding: 3px;"><b xmlns="none">East Melbourne 3000 VIC</b></div><div id="suburb_list_item_5" list_index="5" row_index="12" style="border-width: 1px; border-color: rgb(170, 170, 170); border-style: solid; background-color: rgb(255, 255, 255); padding: 3px;"><b xmlns="none">Footscray 3000 VIC</b></div><div id="suburb_list_item_6" list_index="6" row_index="15" style="border-width: 1px; border-color: rgb(170, 170, 170); border-style: solid; background-color: rgb(221, 221, 221); padding: 3px;"><b xmlns="none">Melbourne 3000 VIC</b></div><div id="suburb_list_item_7" list_index="7" row_index="19" style="border-width: 1px; border-color: rgb(170, 170, 170); border-style: solid; background-color: rgb(255, 255, 255); padding: 3px;"><b xmlns="none">Roxburgh Park 3000 VIC</b></div><div id="suburb_list_item_8" list_index="8" row_index="28" style="border-width: 1px; border-color: rgb(170, 170, 170); border-style: solid; background-color: rgb(221, 221, 221); padding: 3px;"><b xmlns="none">West Melbourne 3000 VIC</b></div></div>
My Code:
for num in range(30):
try:
Element = browser.find_element(By.XPATH, f'//*[#id="suburb_list_item_{num}"]')
print(Element)
except:
break
The two html code at the top are for a input suggestion list and i am trying to scrape of the website. The python code is the code i used and it should print all the elements. But it does not because the suggestion list is clicked. How could i click the text box because this didn't work:
Element = browser.find_element(By.XPATH, '//*[#id="suburb"]')
the element could not be found.
I am not allowed to share the website link.
You can try:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# <insert other code here for setting up the browser>
input_element = wait.until(EC.visibility_of_element_located((By.ID, "suburb")))
input_element.click()
wait = WebDriverWait(browser, 10)
element = wait.until(EC.visibility_of_element_located((By.ID, "suburb_list")))
Is there a way to remove the container background (seen in attached pix as white around the rounded top/bottom of the scroll bar.
Here's my stylesheet:
QScrollBar:horizontal, QScrollBar:vertical
{border: none; border-radius: 0.5em; background-color: #bfbfbf; margin: 0px; padding: 0px;}
QScrollBar:horizontal
{height: 1em;}
QScrollBar:vertical
{width: 1em;}
QScrollBar::handle:horizontal, QScrollBar::handle:vertical
{background-color: #404040; border-radius: 0.5em;}
QScrollBar::handle:horizontal, QScrollBar::handle:vertical
{min-width: 1em; min-height: 1em;}
QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal, QScrollBar::add-page:horizontal,
QScrollBar::sub-page:horizontal
{width: 0px;}
QScrollBar::sub-line:vertical, QScrollBar::add-line:vertical, QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical
{height: 0px;}
I am trying to create an app based on ipywidgets. But unfortunately the scroll is not appearing as I expect it to be. Instead the scrolls are appearing on every output element, whereas I want a single scroll if the height of the content in any of the output element exceeds. Moreover it should not cut the visibility of the content in any of the output.
%%html
<style>
.out1{
width: 700px;
height: 400px;
display: flex;
justify-content: center;
padding: 10px 10px 10px 10px;
border: 1px solid black;
}
.out2{
width: 350px;
height: 400px;
display: flex;
justify-content: center;
padding: 20px 5px 10px 10px;
border: 1px solid black;
}
.out3{
width: 350px;
height: 400px;
display: flex;
justify-content: center;
padding: 20px 5px 10px 10px;
border: 1px solid black;
}
.out4{
width: 700px;
height: 400px;
display: flex;
justify-content: center;
padding: 20px 10px 0px 10px;
border: 1px solid black;
}
.out_box{
border: 1px solid black;
height: 800px;
width: 700px;
overflow: auto;
}
</style>
out1=widgets.Output()
out1.add_class('out1')
out2=widgets.Output()
out2.add_class('out2')
out3=widgets.Output()
out3.add_class('out3')
out4=widgets.Output()
out4.add_class('out4')
box1=widgets.Box([out1], scroll=False)
box2=widgets.HBox([out2,out3], scroll=False)
box3=widgets.Box([out4], scroll=False)
out_box=widgets.VBox([box1,box2,box3])
out_box.add_class('out_box')
Attached is the snap, which I am getting. Results with multiple scroll bars. But I want a single scroll bar at the right end.
I am thinking to create a PyQt6 Application.
I want that application to be more beautiful and modern. So I found some good looking css buttons and chose this codepen button:
* {
margin: 0;
padding: 0;
}
html,
body {
box-sizing: border-box;
height: 100%;
width: 100%;
}
body {
background: #FFF;
font-family: 'Noto Sans JP', sans-serif;
font-weight: 400;
}
.buttons {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
text-align: center;
width: 100%;
height: 100%;
margin: 0 auto;
/* padding: 2em 0em; */
}
.container {
align-items: center;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
background-color: #FFF;
padding: 40px 0px;
width: 240px;
}
h1 {
text-align: left;
color: #444;
letter-spacing: 0.05em;
margin: 0 0 0.4em;
font-size: 1em;
}
p {
text-align: left;
color: #444;
letter-spacing: 0.05em;
font-size: 0.8em;
margin: 0 0 2em;
}
.btn {
letter-spacing: 0.1em;
cursor: pointer;
font-size: 14px;
font-weight: 400;
line-height: 45px;
max-width: 160px;
position: relative;
text-decoration: none;
text-transform: uppercase;
width: 100%;
}
.btn:hover {
text-decoration: none;
}
/*btn_background*/
.effect01 {
color: #FFF;
border: 4px solid #000;
box-shadow:0px 0px 0px 1px #000 inset;
background-color: #000;
overflow: hidden;
position: relative;
transition: all 0.3s ease-in-out;
}
.effect01:hover {
border: 4px solid #666;
background-color: #FFF;
box-shadow:0px 0px 0px 4px #EEE inset;
}
/*btn_text*/
.effect01 span {
transition: all 0.2s ease-out;
z-index: 2;
}
.effect01:hover span{
letter-spacing: 0.13em;
color: #333;
}
/*highlight*/
.effect01:after {
background: #FFF;
border: 0px solid #000;
content: "";
height: 155px;
left: -75px;
opacity: .8;
position: absolute;
top: -50px;
-webkit-transform: rotate(35deg);
transform: rotate(35deg);
width: 50px;
transition: all 1s cubic-bezier(0.075, 0.82, 0.165, 1);/*easeOutCirc*/
z-index: 1;
}
.effect01:hover:after {
background: #FFF;
border: 20px solid #000;
opacity: 0;
left: 120%;
-webkit-transform: rotate(40deg);
transform: rotate(40deg);
}
<div class="buttons">
<div class="container">
<h1>光の反射</h1>
<p>Light reflection</p>
<span>Hover</span>
</div>
</div>
My question is: how can I use pyqt's functions to perform the :after.
I guess I cant just use a widget's stylesheet to perform.
Here is the Python Code that I have written so far:
from PyQt6.QtCore import QRect, Qt
from PyQt6.QtGui import QEnterEvent
from PyQt6.QtWidgets import QGraphicsOpacityEffect, QMainWindow, QPushButton
class QButton(QPushButton):
def __init__(self , main_window: QMainWindow):
super().__init__(main_window)
self.main_window = main_window
self.setText("Welcome")
self.render()
def render(self):
self.setStyleSheet("""
QPushButton{
background-color: #2E3440;
letter-spacing: 0.1px;
font-size: 14px;
font-weight: 400;
line-height: 45px;
text-decoration: none;
color: #FFF;
border: 4px solid #4C566A;
}
""")
self.setFlat(True)
self.setCursor(Qt.CursorShape.PointingHandCursor)
self.setGeometry(QRect(200 , 200 , 200 , 50))
def setText(self , text: str):
text = text.upper()
super().setText(text)
def enterEvent(self, event: QEnterEvent) -> None:
self.setStyleSheet("""
background-color: #D8DEE9;
letter-spacing: 0.13em;
color: #2E3440;
border: 0px;
""")
opacity = QGraphicsOpacityEffect()
opacity.setOpacity(.8)
self.setGraphicsEffect(opacity)
return super().enterEvent(event)
class Renderer:
def __init__(self, main_window: QMainWindow) -> None:
self.main_window = main_window
def render(self):
button = QButton(self.main_window)
if __name__ == "__main__":
app = QApplication([])
window = QMainWindow()
renderer = Renderer(window)
renderer.render()
window.show()
exit(app.exec())
Unfortunately, you can't. Qt Style Sheets are fundamentally based on CSS 2.1, and only support its basic implementation (see the syntax documentation).
If you want a more customized and advanced behavior, you have only two options:
subclass the widget and/or use QProxyStyle;
use QML;
I am creating a GUI app with qt5 and pyqt5.
I am trying to create a dark theme but I've got a problem with QComboBox.
When I tried to make a dark background on the QListView I get a white border or whatever its name on top and the bottom of the list.
I tried a lot of ways, like padding or marge changing of values but nothing helped
I tried something mentioned already here
Remove QListView background
But always the same.
QComboBox {
font: 12pt Fira Sans Condensed;
background-color: #2e2e2e;
border-top: 0px solid #3e3e3e;
border-left: 0px solid #3e3e3e;
border-right: 0px solid #3e3e3e;
border-bottom: 2px solid #3e3e3e;
padding: 5%;
max-height: 30px;
min-width: 140px;
color: white;
selection-background-color: #5e5e5e;
}
QComboBox::drop-down {
border: none;
}
QComboBox::down-arrow {
image: url(icons/QComboBox/down-arrow.png);
width: 25px;
height: 25px;
border-width: 0px;
padding-right: 10px;
}
QComboBox::down-arrow:pressed {
position: relative;
top: 1px; left: 1px;
}
QListView {
font: 12pt Fira Sans Condensed;
background-color: #2e2e2e;
outline: 0;
color: white;
selection-background-color: #5e5e5e;
}
QListView::item {
min-height: 20px;
padding: 5%;
}
self.list = QtWidgets.QListView(self.window.comboBox)
self.window.comboBox.addItem("test1")
self.window.comboBox.addItem("test2")
self.window.comboBox.setView(self.list)
Here is what I get
Add I expect something without the white color on the top and bottom of the list
You have to set the color in the QFrame that is the parent of the view() directly:
self.window.comboBox.view().parentWidget().setStyleSheet('background-color: #2e2e2e;')