本文整理汇总了Python中python_qt_binding.QtGui.QWidget.setStyleSheet方法的典型用法代码示例。如果您正苦于以下问题:Python QWidget.setStyleSheet方法的具体用法?Python QWidget.setStyleSheet怎么用?Python QWidget.setStyleSheet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类python_qt_binding.QtGui.QWidget
的用法示例。
在下文中一共展示了QWidget.setStyleSheet方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SimpleGUI
# 需要导入模块: from python_qt_binding.QtGui import QWidget [as 别名]
# 或者: from python_qt_binding.QtGui.QWidget import setStyleSheet [as 别名]
#.........这里部分代码省略.........
forward_base_box.addItem(QtGui.QSpacerItem(400,20))
forward_base_box.addWidget(forward_base_button)
forward_base_box.addItem(QtGui.QSpacerItem(400,20))
base_box.addLayout(forward_base_box)
left_right_base_box = QtGui.QHBoxLayout()
left_base= Base(Base.LEFT, self)
left_base_button = self.create_button('move left',
left_base.create_closure())
right_base= Base(Base.RIGHT, self)
right_base_button= self.create_button('move right',
right_base.create_closure())
left_right_base_box.addItem(QtGui.QSpacerItem(300,20))
left_right_base_box.addWidget(left_base_button)
left_right_base_box.addItem(QtGui.QSpacerItem(50,20))
left_right_base_box.addWidget(right_base_button)
left_right_base_box.addItem(QtGui.QSpacerItem(300,20))
base_box.addLayout(left_right_base_box)
backward_base_box = QtGui.QHBoxLayout()
backward_base= Base(Base.BACKWARD, self)
backward_base_button = self.create_button('move backward',
backward_base.create_closure())
backward_base_box.addItem(QtGui.QSpacerItem(400,20))
backward_base_box.addWidget(backward_base_button)
backward_base_box.addItem(QtGui.QSpacerItem(400,20))
base_box.addLayout(backward_base_box)
large_box.addLayout(base_box)
turn_base_box = QtGui.QHBoxLayout()
counter_base= Base(Base.COUNTER, self)
counter_base_button = self.create_button('\\\n -->',
counter_base.create_closure())
clockwise_base= Base(Base.CLOCKWISE, self)
clockwise_base_button = self.create_button(' /\n<--',
clockwise_base.create_closure())
turn_base_box.addItem(QtGui.QSpacerItem(75,20))
turn_base_box.addWidget(counter_base_button)
turn_base_box.addItem(QtGui.QSpacerItem(225,20))
turn_base_box.addWidget(clockwise_base_button)
turn_base_box.addItem(QtGui.QSpacerItem(100,20))
large_box.addLayout(turn_base_box)
self._widget.setObjectName('SimpleGUI')
self._widget.setLayout(large_box)
context.add_widget(self._widget)
self._widget.setStyleSheet("QWidget { image: url(%s) }" %
(str(os.path.dirname(os.path.realpath(__file__))) +
"/../../rosie_background.jpg"))
def show_text_in_rviz(self, text):
marker = Marker(type=Marker.TEXT_VIEW_FACING, id=0,
lifetime=rospy.Duration(1.5),
pose=Pose(Point(0.5, 0.5, 1.45), Quaternion(0, 0, 0, 1)),
scale=Vector3(0.06, 0.06, 0.06),
header=Header(frame_id='base_link'),
color=ColorRGBA(0.0, 1.0, 0.0, 0.8), text=text)
self.marker_publisher.publish(marker)
def sound_cb(self, sound_request):
qWarning('Received sound.')
self.sound_sig.emit(sound_request)
def create_button(self, name, method):
btn = QtGui.QPushButton(name, self._widget)
btn.clicked.connect(method)
btn.setAutoRepeat(True)
return btn
def sound_sig_cb(self, sound_request):
qWarning('Received sound signal.')
#if (sound_request.command == SoundRequest.SAY):
qWarning('Robot said: ' + sound_request.arg)
self.speech_label.setText('Robot said: ' + sound_request.arg)
def command_cb(self):
button_name = self._widget.sender().text()
if (button_name == 'Speak'):
qWarning('Robot will say: ' + self.sound_textbox.text())
self._sound_client.say(self.sound_textbox.text())
def shutdown_plugin(self):
# TODO unregister all publishers here
pass
def save_settings(self, plugin_settings, instance_settings):
# TODO save intrinsic configuration, usually using:
# instance_settings.set_value(k, v)
pass
def restore_settings(self, plugin_settings, instance_settings):
# TODO restore intrinsic configuration, usually using:
# v = instance_settings.value(k)
pass
示例2: ArmGUI
# 需要导入模块: from python_qt_binding.QtGui import QWidget [as 别名]
# 或者: from python_qt_binding.QtGui.QWidget import setStyleSheet [as 别名]
#.........这里部分代码省略.........
left_pose_option_box = QtGui.QHBoxLayout()
right_pose_option_box = QtGui.QHBoxLayout()
right_pose_option_box.addWidget(self.create_button('Move to pose (R)'))
left_pose_option_box.addWidget(self.create_button('Move to pose (L)'))
# Buttons for deleting poses for left/right arms
left_pose_option_box.addWidget(self.create_button('Delete pose (L)'))
right_pose_option_box.addWidget(self.create_button('Delete pose (R)'))
left_arm_box.addLayout(left_pose_option_box)
right_arm_box.addLayout(right_pose_option_box)
left_arm_box.addItem(QtGui.QSpacerItem(50,50))
right_arm_box.addItem(QtGui.QSpacerItem(50,50))
arm_box.addLayout(left_arm_box)
arm_box.addItem(QtGui.QSpacerItem(20, 20))
arm_box.addLayout(right_arm_box)
large_box.addLayout(arm_box)
# Initialize state of saved arm poses for selected dropdowns
self.update_saved_l_arm_pose()
self.update_saved_r_arm_pose()
# Update saved arm pose data on the changing of selected pose
self.combo_box_left.connect(self.combo_box_left,
QtCore.SIGNAL("currentIndexChanged(QString)"), self.update_saved_l_arm_pose)
self.combo_box_right.connect(self.combo_box_right,
QtCore.SIGNAL("currentIndexChanged(QString)"), self.update_saved_r_arm_pose)
self._widget.setObjectName('ArmGUI')
self._widget.setLayout(large_box)
context.add_widget(self._widget)
self._widget.setStyleSheet("QWidget { image: url(%s) }" %
(str(os.path.dirname(os.path.realpath(__file__))) +
"/../../arm_gui_bg_large.png"))
rospy.loginfo('GUI initialization complete.')
def create_button(self, name, method=None):
if method == None:
method = self.command_cb
btn = QtGui.QPushButton(name, self._widget)
btn.clicked.connect(method)
return btn
def command_cb(self):
button_name = self._widget.sender().text()
if (button_name == 'Relax right arm'):
self.relax_arm('r')
elif (button_name == 'Freeze right arm'):
self.freeze_arm('r')
elif (button_name == 'Relax left arm'):
self.relax_arm('l')
elif (button_name == 'Freeze left arm'):
self.freeze_arm('l')
elif (button_name == 'Move to pose (R)'):
self.move_arm('r')
elif (button_name == 'Move to pose (L)'):
self.move_arm('l')
elif (button_name == 'Delete pose (L)'):
self.delete_pose_left()
elif (button_name == 'Delete pose (R)'):
self.delete_pose_right()
def update_saved_l_arm_pose(self):
selected_index = self.combo_box_left.currentIndex()
示例3: SimpleGUI
# 需要导入模块: from python_qt_binding.QtGui import QWidget [as 别名]
# 或者: from python_qt_binding.QtGui.QWidget import setStyleSheet [as 别名]
#.........这里部分代码省略.........
base_box = QtGui.QVBoxLayout()
large_box.addItem(QtGui.QSpacerItem(100,100))
#forward
forward_base_box = QtGui.QHBoxLayout()
forward_base = Base(Base.FORWARD)
forward_base_button = self.create_button('move forward', forward_base.create_closure())
forward_base_box.addItem(QtGui.QSpacerItem(400,20))
forward_base_box.addWidget(forward_base_button)
forward_base_box.addItem(QtGui.QSpacerItem(400,20))
base_box.addLayout(forward_base_box)
#large_box.addWidget(forward_base_button)
#left
left_right_base_box = QtGui.QHBoxLayout()
left_base= Base(Base.LEFT)
left_base_button = self.create_button('move left', left_base.create_closure())
#large_box.addWidget(left_base_button)
#right
right_base= Base(Base.RIGHT)
right_base_button= self.create_button('move right', right_base.create_closure())
left_right_base_box.addItem(QtGui.QSpacerItem(300,20))
left_right_base_box.addWidget(left_base_button)
left_right_base_box.addItem(QtGui.QSpacerItem(50,20))
left_right_base_box.addWidget(right_base_button)
left_right_base_box.addItem(QtGui.QSpacerItem(300,20))
base_box.addLayout(left_right_base_box)
#large_box.addWidget(right_base_button)
#backward
backward_base_box = QtGui.QHBoxLayout()
backward_base= Base(Base.BACKWARD)
backward_base_button = self.create_button('move backward', backward_base.create_closure())
backward_base_box.addItem(QtGui.QSpacerItem(400,20))
backward_base_box.addWidget(backward_base_button)
backward_base_box.addItem(QtGui.QSpacerItem(400,20))
base_box.addLayout(backward_base_box)
#large_box.addWidget(backward_base_button)
large_box.addLayout(base_box)
turn_base_box = QtGui.QHBoxLayout()
#turn left
turnleft_base= Base(Base.TURNLEFT)
turnleft_base_button = self.create_button(' /\n<--', turnleft_base.create_closure())
#large_box.addWidget(turnleft_base_button)
#turn right
turnright_base= Base(Base.TURNRIGHT)
turnright_base_button = self.create_button('\\\n -->', turnright_base.create_closure())
turn_base_box.addItem(QtGui.QSpacerItem(75,20))
turn_base_box.addWidget(turnright_base_button)
turn_base_box.addItem(QtGui.QSpacerItem(225,20))
turn_base_box.addWidget(turnleft_base_button)
turn_base_box.addItem(QtGui.QSpacerItem(100,20))
large_box.addLayout(turn_base_box)
#large_box.addWidget(turnright_base_button)
self._widget.setObjectName('SimpleGUI')
self._widget.setLayout(large_box)
context.add_widget(self._widget)
self._widget.setStyleSheet("QWidget { image: url(%s) }" % "/home/vjampala/catkin_ws/src/cse481/hw1/rqt_simplegui/rosie_background.jpg")
def sound_cb(self, sound_request):
qWarning('Received sound.')
self.sound_sig.emit(sound_request)
def create_button(self, name, method):
btn = QtGui.QPushButton(name, self._widget)
btn.clicked.connect(method)
return btn
def sound_sig_cb(self, sound_request):
qWarning('Received sound signal.')
#if (sound_request.command == SoundRequest.SAY):
qWarning('Robot said: ' + sound_request.arg)
self.speech_label.setText('Robot said: ' + sound_request.arg)
def command_cb(self):
button_name = self._widget.sender().text()
if (button_name == 'Speak'):
qWarning('Robot will say: ' + self.sound_textbox.text())
self._sound_client.say(self.sound_textbox.text())
def shutdown_plugin(self):
# TODO unregister all publishers here
pass
def save_settings(self, plugin_settings, instance_settings):
# TODO save intrinsic configuration, usually using:
# instance_settings.set_value(k, v)
pass
def restore_settings(self, plugin_settings, instance_settings):
# TODO restore intrinsic configuration, usually using:
# v = instance_settings.value(k)
pass
示例4: SysCheck
# 需要导入模块: from python_qt_binding.QtGui import QWidget [as 别名]
# 或者: from python_qt_binding.QtGui.QWidget import setStyleSheet [as 别名]
class SysCheck(Plugin):
def __init__(self, context):
super(SysCheck, self).__init__(context)
# Set the name of the object
# (Usually should be the same as the class name)
self.setObjectName('SysCheck')
# Get the thruster parameters
self.names = []
try:
self.names = rospy.get_param('thrusters/mapping')
except KeyError:
print "Thruster mapping not loaded into parameter server"
# Setup the publisher and message object for sending thruster messages
self.pub = rospy.Publisher('thruster', thruster, queue_size=1)
self.thrusterMessage = thruster()
# Subscribe to the depth and orientation topics
self.depth_sub = rospy.Subscriber('depth', Float32Stamped,
self.depthSubCallback, queue_size=1)
self.imu_sub = rospy.Subscriber('pretty/orientation',
Euler,
self.imuSubCallback, queue_size=1)
# Initialize the timers
self.depthTimer = QTimer(self)
self.imuTimer = QTimer(self)
self.sendTimer = QTimer(self)
self.depthTimer.timeout.connect(self.depthMissed)
self.imuTimer.timeout.connect(self.imuMissed)
self.sendTimer.timeout.connect(self.sendMessage)
self.depthTimer.start(1000)
self.imuTimer.start(1000)
# Only start the param timer if the params aren't loaded
if len(self.names) == 0:
self.paramTimer = QTimer(self)
self.paramTimer.timeout.connect(self.loadParam)
self.paramTimer.start(1000)
# Create QWidget
self._widget = QWidget()
# Get path to UI file which should be in the "resource" folder of
# this package
ui_file = os.path.join(rospkg.RosPack().get_path('robosub'),
'src/rqt/rqt_syscheck/resource', 'SysCheck.ui')
# Extend the widget with all attributes and children from UI file
loadUi(ui_file, self._widget)
# Give QObjects a name (Usually the class name + 'Ui')
self._widget.setObjectName('SysCheckUi')
# Add RoboSub Logo to the GUI
logo_file = os.path.join(rospkg.RosPack().get_path('robosub'),
'src/rqt/resource', 'robosub_logo.png')
self._widget.setStyleSheet(".QWidget {background-image: url(" +
logo_file +
"); background-repeat: no-repeat;" +
"background-position:bottom right}")
# Hide the stale labels on init
self._widget.imuStale.hide()
self._widget.depthStale.hide()
# Connect the valueChanged signal to our updateSpeed function
self._widget.thrusterSpeed.valueChanged[int].connect(self.updateSpeed)
self._widget.thrusterEnable.setCheckable(True)
self._widget.thrusterEnable.toggled[bool].connect(self.enable)
self._widget.thrusterKill.clicked[bool].connect(self.kill)
# Load in the thruster buttons and connect callbacks
self.thrusterButtons = []
self.thrusterScales = []
self.thrusterCallbacks = {}
self.loadThrusters()
# If the context is not the root add the serial number to the window
# title
if context.serial_number() > 1:
self._widget.setWindowTitle(self._widget.windowTitle() +
(' (%d)' % context.serial_number()))
# Add widget to the user interface
context.add_widget(self._widget)
def kill(self):
for i in self.thrusterButtons:
i.setChecked(False)
self._widget.thrusterSpeed.setValue(0)
def enable(self, s):
#.........这里部分代码省略.........
示例5: Control
# 需要导入模块: from python_qt_binding.QtGui import QWidget [as 别名]
# 或者: from python_qt_binding.QtGui.QWidget import setStyleSheet [as 别名]
class Control(Plugin):
def __init__(self, context):
super(Control, self).__init__(context)
# Give QObjects reasonable names
self.setObjectName('Control')
# Create QWidget
self._widget = QWidget()
# Get path to UI file which should be in the "resource" folder of
# this package
ui_file = os.path.join(rospkg.RosPack().get_path('robosub'),
'src/rqt/rqt_control/resource', 'Control.ui')
# Extend the widget with all attributes and children from UI file
loadUi(ui_file, self._widget)
self.control_timer = QTimer(self)
self.control_timer.timeout.connect(self.control_missed)
self.control_timer.start(1000)
self.control_status_timer = QTimer(self)
self.control_status_timer.timeout.connect(self.control_status_missed)
self.control_status_timer.start(1000)
# Give QObjects reasonable names
self._widget.setObjectName('Control')
if context.serial_number() > 1:
self._widget.setWindowTitle(self._widget.windowTitle() +
(' (%d)' % context.serial_number()))
# Add widget to the user interface
context.add_widget(self._widget)
self._widget.statusActive.hide()
self._widget.controlActive.hide()
self.con_sub = rospy.Subscriber('control', control,
self.control_callback, queue_size=1)
self.cs_sub = rospy.Subscriber('control_status', control_status,
self.control_status_callback,
queue_size=1)
img_file = os.path.join(rospkg.RosPack().get_path('robosub'),
'src/rqt/resource/robosub_logo.png')
self._widget.setStyleSheet(".QWidget {background-image: url(" +
img_file +
"); background-repeat: no-repeat;" +
"background-position:bottom right}")
def control_missed(self):
if not self._widget.controlStale.isVisible():
self._widget.controlStale.show()
self._widget.controlActive.hide()
def control_status_missed(self):
if not self._widget.statusStale.isVisible():
self._widget.statusStale.show()
self._widget.statusActive.hide()
def control_status_callback(self, m):
try:
self.control_status_timer.stop()
except RuntimeError:
pass
if self._widget.statusStale.isVisible():
self._widget.statusStale.setVisible(False)
self._widget.statusActive.setVisible(True)
# Set the states
self._widget.forwardStatusState.setText(m.forward_state)
self._widget.strafeStatusState.setText(m.strafe_left_state)
self._widget.diveStatusState.setText(m.dive_state)
self._widget.rollStatusState.setText(m.roll_right_state)
self._widget.pitchStatusState.setText(m.pitch_down_state)
self._widget.yawStatusState.setText(m.yaw_left_state)
self._widget.forwardGoal.setText("{:.4f}".format(m.forward_goal))
self._widget.strafeGoal.setText("{:.4f}".format(m.strafe_left_goal))
self._widget.diveGoal.setText("{:.4f}".format(m.dive_goal))
self._widget.rollGoal.setText("{:.4f}".format(m.roll_right_goal))
self._widget.pitchGoal.setText("{:.4f}".format(m.pitch_down_goal))
self._widget.yawGoal.setText("{:.4f}".format(m.yaw_left_goal))
self.control_status_timer.start(1000)
def control_callback(self, m):
try:
self.control_timer.stop()
except RuntimeError:
pass
if self._widget.controlStale.isVisible():
self._widget.controlStale.hide()
self._widget.controlActive.show()
# Set the states
self._widget.forwardState.setText(state_types[m.forward_state])
#.........这里部分代码省略.........
示例6: WaterPulse
# 需要导入模块: from python_qt_binding.QtGui import QWidget [as 别名]
# 或者: from python_qt_binding.QtGui.QWidget import setStyleSheet [as 别名]
#.........这里部分代码省略.........
left_right_base_box.addItem(QtGui.QSpacerItem(300,20))
base_box.addLayout(left_right_base_box)
backward_base_box = QtGui.QHBoxLayout()
backward_base= Base(Base.BACKWARD, self)
backward_base_button = self.create_button('move backward',
backward_base.create_closure())
backward_base_box.addItem(QtGui.QSpacerItem(400,20))
backward_base_box.addWidget(backward_base_button)
backward_base_box.addItem(QtGui.QSpacerItem(400,20))
base_box.addLayout(backward_base_box)
large_box.addLayout(base_box)
turn_base_box = QtGui.QHBoxLayout()
counter_base= Base(Base.COUNTER, self)
counter_base_button = self.create_button('\\\n -->',
counter_base.create_closure())
clockwise_base= Base(Base.CLOCKWISE, self)
clockwise_base_button = self.create_button(' /\n<--',
clockwise_base.create_closure())
turn_base_box.addItem(QtGui.QSpacerItem(75,20))
turn_base_box.addWidget(counter_base_button)
turn_base_box.addItem(QtGui.QSpacerItem(225,20))
turn_base_box.addWidget(clockwise_base_button)
turn_base_box.addItem(QtGui.QSpacerItem(100,20))
large_box.addLayout(turn_base_box)
self._widget.setObjectName('WaterPulse')
self._widget.setLayout(large_box)
context.add_widget(self._widget)
self._widget.setStyleSheet("QWidget { image: url(%s) }" %
(str(os.path.dirname(os.path.realpath(__file__))) +
"/../../rosie_background.jpg"))
def show_text_in_rviz(self, text):
marker = Marker(type=Marker.TEXT_VIEW_FACING, id=0,
lifetime=rospy.Duration(1.5),
pose=Pose(Point(0.5, 0.5, 1.45), Quaternion(0, 0, 0, 1)),
scale=Vector3(0.06, 0.06, 0.06),
header=Header(frame_id='base_link'),
color=ColorRGBA(0.0, 1.0, 0.0, 0.8), text=text)
self.marker_publisher.publish(marker)
def sound_cb(self, sound_request):
qWarning('Received sound.')
self.sound_sig.emit(sound_request)
def create_button(self, name, method):
btn = QtGui.QPushButton(name, self._widget)
btn.clicked.connect(method)
btn.setAutoRepeat(True)
return btn
def sound_sig_cb(self, sound_request):
qWarning('Received sound signal.')
#if (sound_request.command == SoundRequest.SAY):
qWarning('Robot said: ' + sound_request.arg)
def command_cb(self):
button_name = self._widget.sender().text()
if (button_name == 'Speak'):
示例7: Milestone1GUI
# 需要导入模块: from python_qt_binding.QtGui import QWidget [as 别名]
# 或者: from python_qt_binding.QtGui.QWidget import setStyleSheet [as 别名]
#.........这里部分代码省略.........
box_8.addItem(QtGui.QSpacerItem(15,2))
box_8.addWidget(self.book_textbox)
box_8.addWidget(self.create_button('Pick Up Book', self.pick_up_from_shelf_button))
box_8.addItem(QtGui.QSpacerItem(445,2))
box_9.addItem(QtGui.QSpacerItem(15,2))
box_9.addWidget(self.create_button('Localize', self.spin_base))
box_9.addItem(QtGui.QSpacerItem(445,2))
box_10.addItem(QtGui.QSpacerItem(15,2))
box_10.addWidget(self.create_button('Non-nav Pick Up', self.pick_up_from_shelf))
box_10.addItem(QtGui.QSpacerItem(445,2))
button_box.addItem(QtGui.QSpacerItem(20,120))
button_box.addLayout(box_1)
button_box.addLayout(box_2)
button_box.addLayout(box_3)
button_box.addLayout(box_5)
button_box.addLayout(box_4)
button_box.addLayout(box_6)
button_box.addLayout(box_7)
button_box.addLayout(box_8)
button_box.addLayout(box_9)
button_box.addLayout(box_10)
button_box.addItem(QtGui.QSpacerItem(20,240))
large_box.addLayout(button_box)
self.marker_perception = ReadMarkers()
self.speech_recognition = SpeechRecognition(self)
self.bookDB = BookDB()
self.book_map = self.bookDB.getAllBookCodes()
self._widget.setObjectName('Milestone1GUI')
self._widget.setLayout(large_box)
context.add_widget(self._widget)
self._widget.setStyleSheet("QWidget { image: url(%s) }" %
(str(os.path.dirname(os.path.realpath(__file__))) +
"/../../librarian_gui_background.jpg"))
def get_function(self, text):
functions = {
"bring-me-a-book":
self.pick_up_from_shelf_routine,
"put-this-book-back":
self.prepare_to_take,
"give-me-information":
self.give_information_routine,
"here-you-go":
self.put_this_book_back_routine,
}
if text not in functions:
print ("Could not find key %s" % text)
return None
return functions[text]
def sound_cb(self, sound_request):
qWarning('Received sound.')
self.sound_sig.emit(sound_request)
def create_button(self, name, method):
btn = QtGui.QPushButton(name, self._widget)
btn.clicked.connect(method)
btn.setAutoRepeat(True)
return btn
def prepare_to_take(self):
# Open gripper and move arms to take book
self.torso.move(.15) # move torso .1 meter from base (MAX is .2)