python - Using the space next to tabs for displaying text and images - TagMerge
5Using the space next to tabs for displaying text and imagesUsing the space next to tabs for displaying text and images

Using the space next to tabs for displaying text and images

Asked 1 years ago
1
5 answers

You can separate the QTabWidget into a QTabBar and a QStackedWidget, and connect them using connect(tab_bar, &QTabBar::currentChanged, stacked_widget, &QStackedWidget::setCurrentIndex);. Then, you can add whatever next to the tab bar like this.

Suggested layout

Source: link

0

A good suggestion from @Minh... that would provide quite a bit of flexibility. However, this answer suggested using the 'corner widget' which sounded better since I won't lose some of the given functionality of QTabWidget.

I gave it a try and it does what I wanted; within my QTabWidget class, I now have:

    # Image and text labels
    qlabel_img = QtWidgets.QLabel()
    pixmap = QtGui.QPixmap('image.png')
    qlabel_img.setPixmap(pixmap)
    qlabel_txt = QtWidgets.QLabel(f"Text under image")

    # Corner widget
    corner_widget = QtWidgets.QWidget()
    corner_layout = QtWidgets.QVBoxLayout()
    corner_layout.addWidget(qlabel_img)
    corner_layout.addWidget(qlabel_txt)
    corner_widget.setLayout(corner_layout)
    self.setCornerWidget(corner_widget)

and so corner_widget is displayed at the top right (right justified) of the tab widget.

Source: link

0

For example, with the phrasing "extra    space" using a double space, we have the following code in our HTML.
extra    space
If you are pasting text with extra spaces or tabs, you can use the HTML
 tag to keep the text formatted. Below is an example of how to paste text with extra spaces using the 
 tag.
This    text   has    lots of     spaces
The example above is done using the below HTML code.
<pre class="tab">This    text      has    lots of     spaces
The example above was created using the code below.
<p style="margin-left: 2.5em;padding: 0 7em 2em 0;border-width: 2px; border-color: black; border-style:solid;">Example of a paragraph with margin and padding.

A tab can be created in HTML by adjusting the left margin of an element. For example, this paragraph has a left margin of 2.5 em from the element containing the text. The CSS to create this left margin is shown below.
.tab {
 margin-left: 2.5em
}

Source: link

0

How can I change the spaces into tabs? It's driving me crazy. (I'm a beginner in programming). I would be glad if I could get some overall tips on my code, if I have done a lot of mistakes I would be happy to hear.
import random

attraktioner = ["frittfall","bergodalbana","spökhuset"]


class Nojesfalt:
    def __init__(self, attraktion):
        self.val = attraktion
        self.langd = 0
        self.alder = 0


#längdgräns för fritt fall
    def langdgrans(self):
        print("")
        self.langd = int(input("Hur lång är du i cm? "))
        if self.langd < 140:
            print("tyvärr, du är för kort, prova något annat")
            return 0
        elif self.langd >= 140:
            print("håll dig hatten, nu åker vi!")
            print(" ")
            return 1

#åldersgräns för spökhuset
    def aldersgrans(self):
        print("")
        self.alder = int(input("Hur gammal är du? "))
        if self.alder < 10:
            print("tyvärr, du är för ung, prova något annat")
            return 0
        elif self.alder >= 10:
            print("Gå in om du törs!")
            print(" ")
            return 1


#åker attraktion frittfall lr bergodalbana
        def aka(self):
                print("")
        print(self.val)
        tal = random.randint(0,100)
        if tal < 20:
            print("åkturen gick åt skogen, bättre lycka nästa gång")
        elif tal >= 20:
            print("jabbadabbbadoooooooo")
            return 1

#går i spökhuset
        def aka1(self):
                print("")
        print(self.val)
        tal = random.randint(0,100)
        if tal < 20:
            print("du är omringad av spöken och kan inte fortsätta")            return 0
        elif tal >= 20:
            print("Buhuuuuuu, buuuhuuuu")
            return 1

#programkod
print("Välkommen till nöjesfältet, vad vill du göra?")
print(" ")

while 1:
    vald_attr = input("Vad vill du göra?\n1. frittfall\n2. bergodalbana\n3. spökhuset\n4. Avsluta\n")
    if vald_attr == "1":
        val = Nojesfalt(attraktioner[0])
        if val.langdgrans() == 1:
            val.aka()
    elif vald_attr == "2":
        val = Nojesfalt(attraktioner[1])
        val.aka()
    elif vald_attr == "3":
        val = Nojesfalt(attraktioner[2])
        if val.aldersgrans() == 1:
            val.aka1()
    elif vald_attr == "4":
        break
Using the autopep8 command below fixed it for me:
autopep8 -i my_file.py
On command line, you can use a sed line (adapt the number of spaces to whatever pleases you):
sed -e 's;\t;       ;' < yourFile.py > yourNedFile.py
Python.sublime-settings
{
    "tab_size": 4,
    "translate_tabs_to_spaces": true
}
SUBLIME TEXT
while run:

    clock.tick(27)
    
    milli = clock.tick()
    seconds = milli/1000
    timeForLevel += seconds
    print(timeForLevel)

Source: link

0

Example
<button class="tablink" onclick="openPage('Home', this, 'red')">Home</button>
  <button class="tablink" onclick="openPage('News', this, 'green')" 
  id="defaultOpen">News</button><button class="tablink" onclick="openPage('Contact', 
  this, 'blue')">Contact</button><button class="tablink" onclick="openPage('About', 
  this, 'orange')">About</button><div id="Home" class="tabcontent">  <h3>Home</h3>  

Home is where the heart is..

</div><div id="News" class="tabcontent">  <h3>News</h3> 

Some news this fine day!

</div><div id="Contact" class="tabcontent">  <h3>Contact</h3> 

Get in touch, or swing by for a cup of coffee.

</div><div id="About" class="tabcontent">  <h3>About</h3> 

Who we are and what we do.

</div>
Example
/* Set height of body and the document to 100% to enable "full page tabs" */
  body, html {  
  height: 100%;  margin: 0;  font-family: Arial;}/* Style tab links */
  .tablink {  background-color: #555;  color: white;  
  float: left;  border: none;  outline: none;  
  cursor: pointer;  padding: 14px 16px;  font-size: 17px;  
  width: 25%;}.tablink:hover {  
  background-color: #777;}/* Style the tab content (and add 
  height:100% for full page content) */.tabcontent {  color: white;  
  display: none;  padding: 100px 20px;  height: 100%;}#Home 
  {background-color: red;}#News {background-color: green;}#Contact 
  {background-color: blue;}#About {background-color: orange;}
Example
function 
  openPage(pageName, elmnt, color) {  // Hide all 
  elements with class="tabcontent" by default */  var i, 
  tabcontent, tablinks;  tabcontent = 
  document.getElementsByClassName("tabcontent");  for (i = 
  0; i < tabcontent.length; i++) {    
  tabcontent[i].style.display = "none";  }
    // Remove the background color of all tablinks/buttons  
  tablinks = document.getElementsByClassName("tablink");  
  for (i = 0; i < tablinks.length; i++) {    
  tablinks[i].style.backgroundColor = "";  }
    // Show the specific tab content  document.getElementById(pageName).style.display = "block";
    
  // Add the specific color to the button used to open the tab content  elmnt.style.backgroundColor = color;}// Get the element with id="defaultOpen" 
  and click on itdocument.getElementById("defaultOpen").click();

Source: link

Recent Questions on python

    Programming Languages