Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:38:17+00:00 2026-06-09T04:38:17+00:00

#!!/usr/bin/python # Qt modules from PyQt4 import QtCore, QtGui import sys class gui(QtGui.QDialog): def

  • 0
#!!/usr/bin/python

# Qt modules
from PyQt4 import QtCore, QtGui
import sys

class gui(QtGui.QDialog):
    def __init__(self, parent=None):
        QtGui.QDialog.__init__(self, parent)

        self.setWindowTitle('Grid of buttons')
        self.resize(450, 300)


#------------------------------------------------------------------------------ 
#       WIDGETS
#------------------------------------------------------------------------------

        self.grid = QtGui.QGridLayout()

        btnNum = 1
        columnCount = 0
        rowCount = 0

        while btnNum != 26:
            button = QtGui.QPushButton(str(btnNum))
            self.grid.addWidget(button, rowCount, columnCount)
            btnNum += 1

            if columnCount == 4:
                columnCount = 0
                rowCount += 1
            else:
                columnCount += 1

#------------------------------------------------------------------------------ 
#       LAYOUT
#------------------------------------------------------------------------------ 
        self.idChannelGroup = QtGui.QGroupBox("My Button Layout")
        self.idChannelGroup.setLayout(self.grid)

        self.mainLayout = QtGui.QVBoxLayout()
        self.mainLayout.addWidget(self.idChannelGroup)

        self.setLayout(self.mainLayout)   

def main():

    app = QtGui.QApplication(sys.argv)
    ex = gui()
    ex.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

Hi all… I’ve two questions regarding the use of QPushButton. I am pretty new to Qt so I apologies in advance if these seem a little daft…

Firstly, is there any way to keep the QPushButton depressed i.e. remains selected?

Secondly, query all the buttons and find out which button is presently the selected one? Assuming that it would release when another button is clicked? So there would only ever be a single button selected.

Any help would be great. Thank you.

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:38:18+00:00Added an answer on June 9, 2026 at 4:38 am

    Firstly, is there any way to keep the QPushButton depressed i.e. remains selected?

    Yes, you make it ‘checkable’ (setCheckable(true)), it is ‘down’ when ‘checked’.

    … So there would only ever be a single button selected.

    For that, just add your buttons to a QButtonGroup. It defaults to being exclusive, so clicking one will unpress any other.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the code below: #!/usr/bin/env python from PyQt4 import QtCore, QtGui import os,sys class
#!/usr/bin/python # -*- coding: iso-8859-1 -*- import Tkinter import twitter class simpleapp_tk(Tkinter.Tk): def __init__(self,parent):
#!/usr/bin/python # -*- coding: iso-8859-1 -*- import Tkinter class simpleapp_tk(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.parent=parent
I tried this: #!/usr/bin/python from wsgiref.simple_server import make_server from cgi import parse_qs, escape import
my views.py file code: #!/usr/bin/python from django.template import loader, RequestContext from django.http import HttpResponse
This is my piece of code: #!/usr/bin/python from xml.etree.ElementTree import ElementTree from array import
Firstly, here's my script: #!/usr/bin/python import sys, os sys.path.append('/home/username/python') sys.path.append(/home/username/python/flup) sys.path.append(/home/username/python/django) # more path
I'm writing a simple alarm utility in Python. #!/usr/bin/python import time import subprocess import
So I have a file that looks like so: #!/usr/bin/python import MySQLdb import subprocess
I wrote a test program that looked like this: #!/usr/bin/python def incrementc(): c =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.